[] ]; function __construct() { register_activation_hook(__FILE__, array(&$this, 'plugin_init')); $this->settings = get_option($this->key); if (!is_array($this->settings)) { update_option($this->key, $this->default_settings); } $this->settings = get_option($this->key); add_filter("plugin_action_links_" . plugin_basename($this->plugin_path), array(&$this, 'plugins_page_links')); add_filter('plugin_row_meta', array(&$this, 'plugins_page_links_meta'), 10, 2); add_action('admin_menu', array(&$this, 'insert_menu')); add_action('admin_init', array(&$this, 'init')); add_action('wp_footer', array(&$this, 'load_scripts')); function load_custom_wp_admin_style($hook) { if (strpos($hook, 'announcekit') !== false) { wp_enqueue_script('my_custom_script', plugins_url('admin.js', __FILE__), array('jquery'), 'v1'); wp_enqueue_style('bootstrap', plugins_url('bootstrap.min.css', __FILE__), null, 'v1'); } } add_action('admin_enqueue_scripts', 'load_custom_wp_admin_style'); register_setting($this->key, $this->key, function ($input) { if (sanitize_text_field($_POST['action']) !== 'update') { return $this->settings; } $widget_id = sanitize_text_field($_GET['widget_id']); $widget_url = []; preg_match('/https:\/\/announcekit.app\/widget\/([a-zA-Z0-9]+)/', $input['js_code'], $widget_url); if ($widget_url && $widget_url[0]) { $input['widget_url'] = $widget_url[0]; } $input['type'] = "Float"; preg_match('/"selector"/', $input['js_code'], $type); if (count($type)) { $input['type'] = "Badge / Line"; } preg_match('/"embed"/', $input['js_code'], $embed); if (count($embed)) { $input['type'] = "Embed"; } if ($input['type'] == "Float") { $input['selector'] = null; } if ($widget_id != "") { $this->settings['widget_list'][$widget_id] = $input; } else { array_push($this->settings['widget_list'], $input); } return $this->settings; }); if (isset($_GET['delete_widget_id'])) { array_splice($this->settings['widget_list'], sanitize_text_field($_GET['delete_widget_id']), 1); update_option($this->key, $this->settings); header("Location: options-general.php?page=" . plugin_basename($this->plugin_path)); die(); } } function get_menu_list() { $ml = []; $menuLocations = get_nav_menu_locations(); foreach (array_values($menuLocations) as $key => $menuID) { $menus = wp_get_nav_menu_items($menuID); if (is_array($menus)) { foreach ($menus as $menu) { array_push($ml, $menu); } } } return $ml; } function plugin_init() { update_option($this->key, $this->default_settings); } function insert_menu() { add_options_page($this->plugin_name, $this->plugin_name, 'administrator', $this->plugin_path, array( &$this, 'render_settings_page' )); } function plugins_page_links($links) { $settings_link = '' . __('Settings') . ''; array_push($links, $settings_link); return $links; } function plugins_page_links_meta($links, $file) { if (strpos($file, 'announcekit') !== false) { $settings_link = [ 'demo' => 'Demo', 'documentation' => 'Documentation' ]; $links = array_merge($links, $settings_link); } return $links; } function init() { $first_section = $this->key . "first"; add_settings_section($first_section, null, null, __FILE__); add_settings_field("name", 'Widget name', array(&$this, 'render_settings_field'), __FILE__, $first_section, array( "key" => "widget_name" )); add_settings_field("js_code", 'JS Code', array(&$this, 'render_settings_field'), __FILE__, $first_section, array( "key" => "js_code", "textarea" => true )); add_settings_field("widget_url", null, array(&$this, 'render_settings_field'), __FILE__, $first_section, array( "key" => "widget_url", "hidden" => "true" )); add_settings_field("selector", 'Attach to menu', array(&$this, 'render_settings_field'), __FILE__, $first_section, array( "key" => "selector" )); add_settings_field("position_right", 'Right', array(&$this, 'render_settings_field'), __FILE__, $first_section, array( "key" => "position_right" )); add_settings_field("position_left", 'Left', array(&$this, 'render_settings_field'), __FILE__, $first_section, array( "key" => "position_left" )); add_settings_field("position_top", 'Top', array(&$this, 'render_settings_field'), __FILE__, $first_section, array( "key" => "position_top" )); add_settings_field("position_bottom", 'Bottom', array(&$this, 'render_settings_field'), __FILE__, $first_section, array( "key" => "position_bottom" )); add_settings_field("selector", 'Attach to menu', array(&$this, 'render_settings_field'), __FILE__, $first_section, array( "key" => "selector" )); } function render_settings_field($arg) { $widget_id = sanitize_text_field($_GET['widget_id']); $options = get_option($this->key); $html = ""; $default_attrs = "id='" . $arg["key"] . "' name='" . $this->key . "[" . $arg["key"] . "]'"; if (isset($widget_id)) { $value = $options['widget_list'][$widget_id][$arg["key"]]; } else { $value = $options['widget_list'][$arg["key"]]; } switch ($arg["key"]) { case 'position_top': case 'position_bottom': case 'position_left': case 'position_right': $html = "
Boost user engagement, retention and customer happiness 🎉
Beautifully designed newsfeed powered with fancy widgets and email notifications.
| # | Widget | Type | Attached to | Action |
|---|---|---|---|---|
| title; ?> | Edit / Delete | |||
| Before adding a widget, make sure you have already created it in AnnounceKit. | ||||