script_version; } /** * Get current directory path * * @return string */ public function get_script_location() { return __FILE__; } public static function instance($text_domain) { self::$instance = new self(); return self::$instance->set_text_domain($text_domain); } protected function set_text_domain($val) { $this->text_domain = $val; return $this; } private function default_grid() { return [ 'url' => $this->default_grid_link, 'title' => $this->default_grid_title, 'thumbnail' => $this->default_grid_thumbnail, 'description' => $this->default_grid_desc, ]; } public function set_parent_menu_text($text) { $this->parent_menu_text = $text; return $this; } public function set_default_grid_link($url) { $this->default_grid_link = $url; return $this; } public function set_default_grid_title($title) { $this->default_grid_title = $title; return $this; } public function set_default_grid_desc($title) { $this->default_grid_desc = $title; return $this; } public function set_default_grid_thumbnail($thumbnail) { $this->default_grid_thumbnail = $thumbnail; return $this; } public function set_parent_menu_slug($slug) { $this->parent_menu_slug = $slug; return $this; } public function set_menu_slug($slug) { $this->menu_slug = $slug; return $this; } public function set_plugin_file($plugin_file) { $this->plugin_file = $plugin_file; return $this; } public function set_pro_link($url, $conf = []) { if($url == '') { return $this; } $this->pro_link_conf[] = [ 'url' => $url, 'anchor' => empty($conf['anchor']) ? 'Upgrade To Premium' : $conf['anchor'], 'permission' => empty($conf['permission']) ? 'manage_options' : $conf['permission'], ]; return $this; } /** * Set page grid */ public function set_page_grid($conf = []) { if(!empty($conf['url'])) { $this->grids[] = [ 'url' => $conf['url'], 'title' => empty($conf['title']) ? esc_html__('Default Title', 'metform') : $conf['title'], 'thumbnail' => empty($conf['thumbnail']) ? '' : esc_url($conf['thumbnail']), 'description' => empty($conf['description']) ? '' : $conf['description'], ]; } return $this; } /** * Set wpmet products */ public function set_products( $product = [] ) { $this->products[] = [ 'url' => empty( $product['url'] ) ? '' : esc_url( $product['url'] ), 'title' => empty( $product['title'] ) ? esc_html__( 'Default Title', 'metform' ) : $product['title'], 'thumbnail' => empty( $product['thumbnail'] ) ? '' : esc_url( $product['thumbnail'] ), 'description' => empty( $product['description'] ) ? '' : $product['description'], ]; return $this; } protected function prepare_pro_links() { if(!empty($this->pro_link_conf)) { foreach($this->pro_link_conf as $conf) { add_submenu_page($this->parent_menu_slug, $conf['anchor'], $conf['anchor'], $conf['permission'], $conf['url'], ''); } } } protected function prepare_grid_links() { if(!empty($this->grids)) { add_submenu_page($this->parent_menu_slug, $this->parent_menu_text, $this->parent_menu_text, 'manage_options', $this->text_domain . $this->menu_slug, [$this, 'generate_grids']); } } public function generate_grids() { /** * Adding default grid at first position */ array_unshift($this->grids, $this->default_grid()); ?>
text_domain.'/pro_awareness/before_grid_contents'); ?>
grids as $grid) { ?>
text_domain.'/pro_awareness/after_grid_contents'); ?>
jQuery(document).ready( function($) { $('.pro_aware').parent().attr('target','_blank'); }); "; } public function insert_plugin_links($links) { foreach($this->action_links as $action_link) { if(!empty($action_link['link']) && !empty($action_link['text'])) { $attributes = ''; if(!empty($action_link['attr'])) { foreach($action_link['attr'] as $key => $val) { $attributes .= $key.'="'.esc_attr($val).'" '; } } $links[] = sprintf(' %s ', $action_link['link'], esc_html($action_link['text'])); } } return $links; } public function insert_plugin_row_meta($links, $file) { if($file == $this->plugin_file) { foreach($this->row_meta_links as $meta) { if(!empty($meta['link']) && !empty($meta['text'])) { $attributes = ''; if(!empty($meta['attr'])) { foreach($meta['attr'] as $key => $val) { $attributes .= $key.'="'.esc_attr($val).'" '; } } $links[] = sprintf(' %s ', $meta['link'], $attributes, esc_html($meta['text'])); } } } return $links; } public function set_plugin_action_link($text, $link, $attr = []) { $this->action_links[] = [ 'text' => $text, 'link' => $link, 'attr' => $attr, ]; return $this; } public function set_plugin_row_meta($text, $link, $attr = []) { $this->row_meta_links[] = [ 'text' => $text, 'link' => $link, 'attr' => $attr, ]; return $this; } public function generate_menus() { add_filter('plugin_action_links_' . $this->plugin_file, [$this, 'insert_plugin_links']); add_filter('plugin_row_meta', [$this, 'insert_plugin_row_meta'], 10, 2); if(!empty($this->parent_menu_slug)) { $this->prepare_grid_links(); $this->prepare_pro_links(); } } public static function init() { add_action('admin_head', [__CLASS__, 'enqueue_scripts']); } public function call() { add_action('admin_menu', [$this, 'generate_menus'], 99999); } } endif;