'capability_here'
* To add a page to the network admin (wp-admin/network), use: 'network_admin_menu' => 'capability_here'
* To add a page to the user (wp-admin/user) admin, use: 'user_admin_menu' => 'capability_here'
*
* @since 2.0.0
* @var array
*/
protected $supported_panels = array(
'network_admin_menu' => 'wu_edit_broadcasts',
);
/**
* Allow child classes to register widgets, if they need them.
*
* @since 1.8.2
* @return void
*/
public function register_widgets() {
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_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'),
),
'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,
)
),
),
));
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.
*
* @since 2.0.0
* @return void
*/
public function output_default_widget_customer_targets() {
$object = $this->get_object();
$all_targets = $object->get_message_targets();
$targets = array();
$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);
$html = '
';
echo $html;
} // end output_default_widget_customer_targets;
/**
* Outputs the markup for the products targets widget.
*
* @since 2.0.0
* @return void
*/
public function output_default_widget_product_targets() {
$object = $this->get_object();
$targets = wu_get_broadcast_targets($object->get_id(), 'products');
$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(),
'width' => '400',
'height' => '360',
);
$link = wu_get_form_url('view_broadcast_targets', $modal_atts);
$image = $product->get_featured_image('thumbnail');
$image = $image ? sprintf('
', esc_attr($image)) : '';
$plan_customers = wu_get_membership_customers($product->get_id());
$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(
'link' => $link,
'avatar' => $image,
'display_name' => $product->get_name(),
'id' => $product->get_id(),
'description' => $description
);
} // end if;
} // end foreach;
} // end if;
$args = array(
'targets' => $product_targets,
'loading_text' => __('Loading...', 'wp-ultimo'),
'wrapper_class' => 'wu-bg-gray-100 wu--mt-3 wu--mb-6 wu--mx-3',
'modal_class' => 'wubox',
);
wu_get_template('broadcast/widget-targets', $args);
} // end output_default_widget_product_targets;
/**
* Returns the title of the page.
*
* @since 2.0.0
* @return string Title of the 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.
*
* @since 2.0.0
* @return string Menu label of the page.
*/
public function get_menu_title() {
return __('Edit Broadcast', 'wp-ultimo');
} // end get_menu_title;
/**
* Returns the action links for that page.
*
* @since 1.8.2
* @return array
*/
public function action_links() {
return array();
} // end action_links;
/**
* Returns the labels to be used on the admin page.
*
* @since 2.0.0
* @return array
*/
public function get_labels() {
return array(
'edit_label' => __('Edit Broadcast', 'wp-ultimo'),
'add_new_label' => __('Add new Broadcast', 'wp-ultimo'),
'updated_message' => __('Broadcast updated with success!', 'wp-ultimo'),
'title_placeholder' => __('Enter Broadcast Title', 'wp-ultimo'),
'title_description' => __('This title is used on the message itself, and in the case of a broadcast email, it will be used as the subject.', 'wp-ultimo'),
'save_button_label' => __('Save Broadcast', 'wp-ultimo'),
'save_description' => '',
'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.
*
* @since 2.0.0
*
* @param array $args Query args passed to the list table.
* @return array Modified query args.
*/
public function query_filter($args) {
$extra_args = array(
'object_type' => 'broadcast',
'object_id' => absint($this->get_object()->get_id()),
);
return array_merge($args, $extra_args);
} // end query_filter;
/**
* Returns the object being edit at the moment.
*
* @since 2.0.0
* @return \WP_Ultimo\Models\Broadcast
*/
public function get_object() {
if (isset($_GET['id'])) {
$query = new \WP_Ultimo\Database\Broadcasts\Broadcast_Query;
$item = $query->get_item_by('id', $_GET['id']);
if (!$item) {
wp_redirect(wu_network_admin_url('wp-ultimo-broadcasts'));
exit;
} // end if;
return $item;
} // end if;
return new Broadcast;
} // end get_object;
/**
* Broadcasts have titles.
*
* @since 2.0.0
*/
public function has_title(): bool {
return true;
} // end has_title;
/**
* Wether or not this pages should have an editor field.
*
* @since 2.0.0
*/
public function has_editor(): bool {
return true;
} // end has_editor;
/**
* Filters the list table to return only relevant events.
*
* @since 2.0.0
*
* @param array $args Query args passed to the list table.
* @return array Modified query args.
*/
public function events_query_filter($args) {
$extra_args = array(
'object_type' => 'broadcast',
'object_id' => absint($this->get_object()->get_id()),
);
return array_merge($args, $extra_args);
} // end events_query_filter;
} // end class Broadcast_Edit_Admin_Page;