Use new code style

This commit is contained in:
David Stone
2025-02-07 19:02:33 -07:00
parent 0181024ae1
commit 8433379d90
672 changed files with 37107 additions and 45249 deletions

View File

@ -12,7 +12,7 @@ namespace WP_Ultimo\Admin_Pages;
// Exit if accessed directly
defined('ABSPATH') || exit;
use \WP_Ultimo\Models\Broadcast;
use WP_Ultimo\Models\Broadcast;
/**
* WP Multisite WaaS Broadcast Edit/Add New Admin Page.
@ -90,62 +90,69 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
parent::register_widgets();
$this->add_list_table_widget('events', array(
'title' => __('Events', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(),
'query_filter' => array($this, 'events_query_filter'),
));
$this->add_list_table_widget(
'events',
array(
'title' => __('Events', 'wp-ultimo'),
'table' => new \WP_Ultimo\List_Tables\Inside_Events_List_Table(),
'query_filter' => array($this, 'events_query_filter'),
)
);
$this->add_save_widget('save', array(
'html_attr' => array(
'data-wu-app' => 'save_broadcast',
'data-state' => wu_convert_to_state(array(
'type' => $this->get_object()->get_type(),
)),
),
'fields' => array(
'type' => array(
'type' => 'select',
'title' => __('Broadcast Type', 'wp-ultimo'),
'placeholder' => __('Type', 'wp-ultimo'),
'desc' => __('Broadcast type cannot be edited.', 'wp-ultimo'),
'options' => array(
'broadcast_email' => __('Email', 'wp-ultimo'),
'broadcast_notice' => __('Admin Notice', 'wp-ultimo'),
$this->add_save_widget(
'save',
array(
'html_attr' => array(
'data-wu-app' => 'save_broadcast',
'data-state' => wu_convert_to_state(
array(
'type' => $this->get_object()->get_type(),
)
),
'value' => $this->get_object()->get_type(),
'tooltip' => '',
'html_attr' => array(
'disabled' => 'disabled',
'name' => ''
)
),
'notice_type' => array(
'type' => 'select',
'title' => __('Broadcast Status', 'wp-ultimo'),
'placeholder' => __('Status', 'wp-ultimo'),
'desc' => __('This option determines the color of the admin notice.', 'wp-ultimo'),
'options' => array(
'info' => __('Info (blue)', 'wp-ultimo'),
'success' => __('Success (green)', 'wp-ultimo'),
'warning' => __('Warning (yellow)', 'wp-ultimo'),
'error' => __('Error (red)', 'wp-ultimo'),
'fields' => array(
'type' => array(
'type' => 'select',
'title' => __('Broadcast Type', 'wp-ultimo'),
'placeholder' => __('Type', 'wp-ultimo'),
'desc' => __('Broadcast type cannot be edited.', 'wp-ultimo'),
'options' => array(
'broadcast_email' => __('Email', 'wp-ultimo'),
'broadcast_notice' => __('Admin Notice', 'wp-ultimo'),
),
'value' => $this->get_object()->get_type(),
'tooltip' => '',
'html_attr' => array(
'disabled' => 'disabled',
'name' => '',
),
),
'notice_type' => array(
'type' => 'select',
'title' => __('Broadcast Status', 'wp-ultimo'),
'placeholder' => __('Status', 'wp-ultimo'),
'desc' => __('This option determines the color of the admin notice.', 'wp-ultimo'),
'options' => array(
'info' => __('Info (blue)', 'wp-ultimo'),
'success' => __('Success (green)', 'wp-ultimo'),
'warning' => __('Warning (yellow)', 'wp-ultimo'),
'error' => __('Error (red)', 'wp-ultimo'),
),
'value' => $this->get_object()->get_notice_type(),
'tooltip' => '',
'wrapper_html_attr' => array(
'v-if' => 'type === "broadcast_notice"',
'v-cloak' => 1,
),
),
'value' => $this->get_object()->get_notice_type(),
'tooltip' => '',
'wrapper_html_attr' => array(
'v-if' => 'type === "broadcast_notice"',
'v-cloak' => 1,
)
),
),
));
)
);
add_meta_box('wp-ultimo-broadcast-customer-targets', __('Customer Targets', 'wp-ultimo'), array($this, 'output_default_widget_customer_targets'), get_current_screen()->id, 'side');
add_meta_box('wp-ultimo-broadcast-product-targets', __('Product Targets', 'wp-ultimo'), array($this, 'output_default_widget_product_targets'), get_current_screen()->id, 'side');
} // end register_widgets;
}
/**
* Outputs the markup for the customer targets widget.
@ -164,16 +171,12 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
$customer_targets = wu_get_isset($all_targets, 'customers', '');
if ($customer_targets) {
if (is_array($all_targets['customers'])) {
$all_targets['customers'] = $all_targets['customers'][0];
} // end if;
}
$targets = explode(',', (string) $all_targets['customers']);
} // end if;
}
$targets_count = count($targets);
@ -201,10 +204,16 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
$customer_link = wu_network_admin_url('wp-ultimo-edit-customer', $url_atts);
$avatar = get_avatar($customer->get_user_id(), 32, 'identicon', '', array(
'force_display' => true,
'class' => 'wu-rounded-full wu-border-solid wu-border-1 wu-border-white hover:wu-border-gray-400',
));
$avatar = get_avatar(
$customer->get_user_id(),
32,
'identicon',
'',
array(
'force_display' => true,
'class' => 'wu-rounded-full wu-border-solid wu-border-1 wu-border-white hover:wu-border-gray-400',
)
);
$display_name = $customer->get_display_name();
@ -222,16 +231,21 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
break;
case $targets_count > 1:
foreach ($targets as $key => $target) {
$customer = wu_get_customer($target);
$tooltip_name = $customer->get_display_name();
$email = $customer->get_email_address();
$avatar = get_avatar($email, 32, 'identicon', '', array(
'class' => 'wu-rounded-full wu-border-solid wu-border-1 wu-border-white hover:wu-border-gray-400',
));
$avatar = get_avatar(
$email,
32,
'identicon',
'',
array(
'class' => 'wu-rounded-full wu-border-solid wu-border-1 wu-border-white hover:wu-border-gray-400',
)
);
$url_atts = array(
'id' => $customer->get_id(),
@ -240,11 +254,9 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
$customer_link = wu_network_admin_url('wp-ultimo-edit-customer', $url_atts);
$html .= "<div class='wu-flex wu--mr-4'><a role='tooltip' aria-label='{$tooltip_name}' href='{$customer_link}'>{$avatar}</a></div>";
} // end foreach;
}
if ($targets_count < 7) {
$modal_atts = array(
'action' => 'wu_modal_targets_display',
'object_id' => $object->get_id(),
@ -253,12 +265,16 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
'target_type' => 'customers',
);
$html .= sprintf('<div class="wu-inline-block wu--mr-4">
$html .= sprintf(
'<div class="wu-inline-block wu--mr-4">
<a href="%s" title="%s" class="wubox wu-no-underline"><span class="wu-ml-6 wu-uppercase wu-text-xs wu-text-gray-600 wu-font-bold"> %s %s</span></a>
</div>', wu_get_form_url('view_broadcast_targets', $modal_atts), __('Targets', 'wp-ultimo'), $targets_count, __('Targets', 'wp-ultimo'));
</div>',
wu_get_form_url('view_broadcast_targets', $modal_atts),
__('Targets', 'wp-ultimo'),
$targets_count,
__('Targets', 'wp-ultimo')
);
} else {
$count = $targets_count - 6;
$modal_atts = array(
@ -269,21 +285,24 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
'target_type' => 'customers',
);
$html .= sprintf('<div class="wu-inline-block wu-ml-4">
$html .= sprintf(
'<div class="wu-inline-block wu-ml-4">
<a href="%s" title="%s" class="wubox wu-no-underline"><span class="wu-pl-2 wu-uppercase wu-text-xs wu-font-bold"> %s %s</span></a>
</div>', wu_get_form_url('view_broadcast_targets', $modal_atts), __('Targets', 'wp-ultimo'), $targets_count, __('Targets', 'wp-ultimo'));
} // end if;
</div>',
wu_get_form_url('view_broadcast_targets', $modal_atts),
__('Targets', 'wp-ultimo'),
$targets_count,
__('Targets', 'wp-ultimo')
);
}
break;
} // end switch;
}
$html .= '</div></li></ul></div>';
echo $html;
} // end output_default_widget_customer_targets;
}
/**
* Outputs the markup for the products targets widget.
@ -300,13 +319,10 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
$product_targets = array();
if ($targets) {
foreach ($targets as $key => $value) {
$product = wu_get_product($value);
if ($product) {
$modal_atts = array(
'action' => 'wu_modal_product_targets_display',
'product_id' => $product->get_id(),
@ -325,27 +341,22 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
$customer_count = (int) 0;
if ($plan_customers) {
$customer_count = count($plan_customers);
} // end if;
}
// translators: %s is the number of customers.
$description = sprintf(__('%s customer(s) targeted.', 'wp-ultimo'), $customer_count);
$product_targets[$key] = array(
$product_targets[ $key ] = array(
'link' => $link,
'avatar' => $image,
'display_name' => $product->get_name(),
'id' => $product->get_id(),
'description' => $description
'description' => $description,
);
} // end if;
} // end foreach;
} // end if;
}
}
}
$args = array(
'targets' => $product_targets,
@ -355,8 +366,7 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
);
wu_get_template('broadcast/widget-targets', $args);
} // end output_default_widget_product_targets;
}
/**
* Returns the title of the page.
@ -367,8 +377,7 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
public function get_title() {
return $this->edit ? __('Edit Broadcast', 'wp-ultimo') : __('Add new Broadcast', 'wp-ultimo');
} // end get_title;
}
/**
* Returns the title of menu for this page.
@ -379,8 +388,7 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
public function get_menu_title() {
return __('Edit Broadcast', 'wp-ultimo');
} // end get_menu_title;
}
/**
* Returns the action links for that page.
@ -391,8 +399,7 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
public function action_links() {
return array();
} // end action_links;
}
/**
* Returns the labels to be used on the admin page.
@ -413,8 +420,7 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
'delete_button_label' => __('Delete Broadcast', 'wp-ultimo'),
'delete_description' => __('Be careful. This action is irreversible.', 'wp-ultimo'),
);
} // end get_labels;
}
/**
* Filters the list table to return only relevant events.
@ -432,8 +438,7 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
);
return array_merge($args, $extra_args);
} // end query_filter;
}
/**
* Returns the object being edit at the moment.
@ -444,26 +449,21 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
public function get_object() {
if (isset($_GET['id'])) {
$query = new \WP_Ultimo\Database\Broadcasts\Broadcast_Query;
$query = new \WP_Ultimo\Database\Broadcasts\Broadcast_Query();
$item = $query->get_item_by('id', $_GET['id']);
if (!$item) {
if ( ! $item) {
wp_redirect(wu_network_admin_url('wp-ultimo-broadcasts'));
exit;
} // end if;
}
return $item;
}
} // end if;
return new Broadcast;
} // end get_object;
return new Broadcast();
}
/**
* Broadcasts have titles.
@ -473,8 +473,7 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
public function has_title(): bool {
return true;
} // end has_title;
}
/**
* Wether or not this pages should have an editor field.
@ -484,8 +483,7 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
public function has_editor(): bool {
return true;
} // end has_editor;
}
/**
* Filters the list table to return only relevant events.
@ -503,7 +501,5 @@ class Broadcast_Edit_Admin_Page extends Edit_Admin_Page {
);
return array_merge($args, $extra_args);
} // end events_query_filter;
} // end class Broadcast_Edit_Admin_Page;
}
}