/**
  * Bootstrap.
  */
 public static function init()
 {
     register_activation_hook(__FILE__, array('Plugin_Name_Bootstrap', 'activate_plugin_name'));
     register_deactivation_hook(__FILE__, array('Plugin_Name_Bootstrap', 'deactivate_plugin_name'));
     /**
      * The core plugin class that is used to define internationalization,
      * admin-specific hooks, and public-facing site hooks.
      */
     require plugin_dir_path(__FILE__) . 'includes/class-plugin-name.php';
     $plugin = new Plugin_Name();
     $plugin->run();
 }
/**
 * Load template files of the plugin also include a filter pn_get_template_part<br>
 * Based on WooCommerce function<br>
 *
 * @package   Plugin_Name
 * @author  Mte90 <*****@*****.**>
 * @license   GPL-2.0+
 * @copyright 2014-2015
 * @since    1.0.0
 */
function pn_get_template_part($slug, $name = '', $include = true)
{
    $template = '';
    $path = plugin_dir_path(realpath(dirname(__FILE__))) . 'templates/';
    $plugin = Plugin_Name::get_instance();
    $plugin_slug = $plugin->get_plugin_slug() . '/';
    // Look in yourtheme/slug-name.php and yourtheme/plugin-name/slug-name.php
    if ($name) {
        $template = locate_template(array("{$slug}-{$name}.php", $plugin_slug . "{$slug}-{$name}.php"));
    } else {
        $template = locate_template(array("{$slug}.php", $plugin_slug . "{$slug}.php"));
    }
    // Get default slug-name.php
    if (!$template && $name && file_exists($path . "{$slug}-{$name}.php")) {
        $template = $path . "{$slug}-{$name}.php";
    }
    // If template file doesn't exist, look in yourtheme/slug.php and yourtheme/woocommerce/slug.php
    if (!$template) {
        $template = locate_template(array("{$slug}.php", $plugin_slug . "{$slug}.php"));
    }
    // Allow 3rd party plugin filter template file from their plugin
    $template = apply_filters('pn_get_template_part', $template, $slug, $name);
    if ($template && $include === true) {
        load_template($template, false);
    } else {
        if ($template && $include === false) {
            return $template;
        }
    }
}
 /**
  * Register the JavaScript for the public-facing side of the site.
  *
  * @since    1.0.0
  */
 public function enqueue_scripts()
 {
     /**
      * This function is provided for demonstration purposes only.
      */
     wp_enqueue_script(Plugin_Name::PLUGIN_ID, Plugin_Name::get_plugin_url() . 'views/js/' . Plugin_Name::PLUGIN_ID . '.js', array('jquery'), Plugin_Name::PLUGIN_VERSION, false);
 }
Ejemplo n.º 4
0
 public static function init()
 {
     if (null == self::$app) {
         self::$app = new Plugin_Name\App();
         self::$app->run();
     }
     return self::$app;
 }
/**
 * Load the plugin text domain for translation.
 *
 * @since    1.0.0
 */
function pn_load_plugin_textdomain()
{
    $plugin = Plugin_Name::get_instance();
    $domain = $plugin->get_plugin_slug();
    $locale = apply_filters('plugin_locale', get_locale(), $domain);
    load_textdomain($domain, trailingslashit(WP_LANG_DIR) . $domain . '/' . $domain . '-' . $locale . '.mo');
    load_plugin_textdomain($domain, FALSE, basename(plugin_dir_path(dirname(__FILE__))) . '/languages/');
}
 /**
  * Register the JavaScript for the admin area.
  *
  * @since    1.0.0
  */
 public function enqueue_styles($hook)
 {
     /**
      * This function is provided for demonstration purposes only.
      *
      */
     wp_enqueue_style(Plugin_Name::PLUGIN_ID . '_admin-css', Plugin_Name::get_plugin_url() . 'views/admin/css/' . Plugin_Name::PLUGIN_ID . '-admin.css', array(), Plugin_Name::PLUGIN_VERSION, 'all');
 }
 /**
  * Initialize the class
  *
  * @since     1.0.0
  */
 private function __construct()
 {
     /**
      * Call $plugin_slug from public plugin class.
      */
     $plugin = Plugin_Name::get_instance();
     $this->plugin_slug = $plugin->get_plugin_slug();
     $this->plugin_version = $plugin->get_plugin_version();
 }
 /**
  * Initialize the plugin by loading admin scripts & styles and adding a
  * settings page and menu.
  *
  * @since     1.0.0
  */
 public function __construct()
 {
     $plugin = Plugin_Name::get_instance();
     $this->plugin_slug = $plugin->get_plugin_slug();
     $this->plugin_name = $plugin->get_plugin_name();
     //Add the export settings method
     add_action('admin_init', array($this, 'settings_export'));
     //Add the import settings method
     add_action('admin_init', array($this, 'settings_import'));
 }
 /**
  * Main Plugin_Name Instance
  *
  * Insures that only one instance of Plugin_Name exists in memory at any one
  * time. Also prevents needing to define globals all over the place.
  *
  * @since 1.4
  * @static
  * @staticvar array $instance
  * @uses Plugin_Name::setup_constants() Setup the constants needed
  * @uses Plugin_Name::includes() Include the required files
  * @uses Plugin_Name::load_textdomain() load the language files
  * @see Plugin_Name()
  * @return The one true Plugin_Name
  */
 public static function instance()
 {
     if (!isset(self::$instance) && !self::$instance instanceof Plugin_Name) {
         self::$instance = new Plugin_Name();
         self::$instance->setup_constants();
         add_action('plugins_loaded', array(self::$instance, 'load_textdomain'));
         self::$instance->includes();
     }
     return self::$instance;
 }
 function __construct()
 {
     $plugin = Plugin_Name::get_instance();
     $this->plugin_slug = $plugin->get_plugin_slug();
     // Configure widget array
     $args = array('label' => __('My Recent Posts', $this->plugin_slug), 'description' => __('My Recent Posts Widget Description', $this->plugin_slug));
     // Configure the widget fields
     // Example for: Title ( text ) and Amount of posts to show ( select box )
     $args['fields'] = array(array('name' => __('Title', $this->plugin_slug), 'desc' => __('Enter the widget title.', $this->plugin_slug), 'id' => 'title', 'type' => 'text', 'class' => 'widefat', 'std' => __('Recent Posts', $this->plugin_slug), 'validate' => 'alpha_dash', 'filter' => 'strip_tags|esc_attr'), array('name' => __('Amount'), 'desc' => __('Select how many posts to show.', $this->plugin_slug), 'id' => 'amount', 'type' => 'select', 'fields' => array(array('name' => __('1 Post', $this->plugin_slug), 'value' => '1'), array('name' => __('2 Posts', $this->plugin_slug), 'value' => '2'), array('name' => __('3 Posts', $this->plugin_slug), 'value' => '3')), 'validate' => 'my_custom_validation', 'filter' => 'strip_tags|esc_attr'), array('name' => __('Output as list', $this->plugin_slug), 'desc' => __('Wraps posts with the <li> tag.', $this->plugin_slug), 'id' => 'list', 'type' => 'checkbox', 'std' => 1, 'filter' => 'strip_tags|esc_attr'));
     // fields array
     // create widget
     $this->create_widget($args);
 }
 /**
  * Initialize the class
  *
  * @since     1.0.0
  */
 private function __construct()
 {
     /*
      * Call $plugin_slug from public plugin class.
      */
     $plugin = Plugin_Name::get_instance();
     $this->plugin_slug = $plugin->get_plugin_slug();
     $this->plugin_version = $plugin->get_plugin_version();
     // Backend hooks and filters
     if (is_admin()) {
         add_action('admin_enqueue_scripts', array($this, 'tinymce_plugin_css'));
         add_action("admin_head", array($this, 'js_ajax_nonce'));
         add_action('admin_init', array($this, 'register_tinymce_plugin'));
         add_action('wp_ajax_admin_shortcode_popup', array($this, 'ajax_admin_shortcode_popup'));
     }
 }
 /**
  * Render a template
  *
  * @param  string $default_template_path The path to the template, relative to the plugin's `views` folder
  * @param  array  $variables             An array of variables to pass into the template's scope, indexed with the variable name so that it can be extract()-ed
  * @param  string $require               'once' to use require_once() | 'always' to use require()
  * @return string
  *
  * @since    1.0.0
  */
 protected static function render_template($default_template_path = false, $variables = array(), $require = 'once')
 {
     if (!($template_path = locate_template(basename($default_template_path)))) {
         $template_path = Plugin_Name::get_plugin_path() . '/views/admin/' . $default_template_path;
     }
     if (is_file($template_path)) {
         extract($variables);
         ob_start();
         if ('always' == $require) {
             require $template_path;
         } else {
             require_once $template_path;
         }
         $template_content = apply_filters('plugin_name_template_content', ob_get_clean(), $default_template_path, $template_path, $variables);
     } else {
         $template_content = '';
     }
     return $template_content;
 }
 /**
  * Initialize the plugin by loading admin scripts & styles and adding a
  * settings page and menu.
  *
  * @since     1.0.0
  */
 private function __construct()
 {
     /*
      * @TODO :
      *
      * - Uncomment following lines if the admin class should only be available for super admins
      */
     /* if( ! is_super_admin() ) {
        return;
        } */
     /*
      * Call $plugin_slug from public plugin class.
      */
     $plugin = Plugin_Name::get_instance();
     $this->plugin_slug = $plugin->get_plugin_slug();
     $this->plugin_version = $plugin->get_plugin_version();
     // Load admin style sheet and JavaScript.
     add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_css_js'));
     // Add the plugin admin pages and menu items.
     add_action('admin_menu', array($this, 'add_plugin_admin_menu'));
 }
 /**
  * Initialize the plugin by loading admin scripts & styles and adding a
  * settings page and menu.
  *
  * @since     1.0.0
  */
 private function __construct()
 {
     /*
      * @TODO :
      *
      * - Uncomment following lines if the admin class should only be available for super admins
      */
     /* if( ! is_super_admin() ) {
        return;
        } */
     /*
      * Call $plugin_slug from public plugin class.
      */
     $plugin = Plugin_Name::get_instance();
     $this->plugin_slug = $plugin->get_plugin_slug();
     $this->plugin_version = $plugin->get_plugin_version();
     // Load admin style sheet and JavaScript.
     //add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_css_js' ) );
     // Add an action link pointing to the options page.
     $plugin_basename = plugin_basename(plugin_dir_path(realpath(dirname(dirname(__FILE__)))) . $this->plugin_slug . '.php');
     add_filter('plugin_action_links_' . $plugin_basename, array($this, 'add_action_links'));
 }
/**
 * Load email template files of the plugin also include a filter pn_get_email_template<br>
 *
 * @package   Plugin_Name
 * @author  Mte90 <*****@*****.**>
 * @license   GPL-2.0+
 * @copyright 2014-2015
 * @since    1.0.0
 */
function pn_get_email_template($name, $prefix = '')
{
    $template = '';
    $folder = 'email-templates/';
    $path = plugin_dir_path(realpath(dirname(__FILE__))) . $folder;
    $plugin = Plugin_Name::get_instance();
    $plugin_slug = $plugin->get_plugin_slug() . '/';
    $locale = apply_filters("plugin_locale", get_locale(), $plugin->get_plugin_slug());
    // Look in yourtheme/plugin-name/{locale}/name.tpl and yourtheme/plugin-name/email-templates/{locale}/name.tpl
    if (empty($template)) {
        $search = array($plugin_slug . $folder . $locale . '/' . $name . '.tpl', $plugin_slug . $folder . 'en_US/' . $name . '.tpl', $plugin_slug . $locale . '/' . $name . '.tpl', $plugin_slug . 'en_US/' . $name . '.tpl');
        if (!empty($prefix)) {
            array_unshift($search, $plugin_slug . 'en_US/' . $prefix . '-' . $name . '.tpl');
            array_unshift($search, $plugin_slug . $folder . 'en_US/' . $prefix . '-' . $name . '.tpl');
            array_unshift($search, $plugin_slug . $locale . '/' . $prefix . '-' . $name . '.tpl');
            array_unshift($search, $plugin_slug . $folder . $locale . '/' . $prefix . '-' . $name . '.tpl');
        }
        $template = locate_template($search);
    }
    // Load the template from plugin folders
    if (!empty($prefix)) {
        if (file_exists($path . $locale . '/' . $prefix . '-' . $name . '.tpl')) {
            $template = $path . $locale . '/' . $prefix . '-' . $name . '.tpl';
        } elseif (file_exists($path . 'en_US/' . $prefix . '-' . $name . '.tpl')) {
            $template = $path . 'en_US/' . $prefix . '-' . $name . '.tpl';
        }
    }
    if (empty($template)) {
        if (file_exists($path . $locale . '/' . $name . '.tpl')) {
            $template = $path . $locale . '/' . $name . '.tpl';
        } elseif (file_exists($path . 'en_US/' . $name . '.tpl')) {
            $template = $path . 'en_US/' . $name . '.tpl';
        }
    }
    // Allow 3rd party plugin filter template file from their plugin
    $template = apply_filters('pn_get_email_template', $template, $name, $prefix);
    return wpautop(file_get_contents($template));
}
 /**
  * Initialize the plugin by loading admin scripts & styles and adding a
  * settings page and menu.
  *
  * @since     1.0.0
  */
 private function __construct()
 {
     /*
      * @TODO :
      *
      * - Uncomment following lines if the admin class should only be available for super admins
      */
     /* if( ! is_super_admin() ) {
     			return;
     		} */
     /*
      * Call $plugin_slug from public plugin class.
      *
      * @TODO:
      *
      * - Rename "Plugin_Name" to the name of your initial plugin class
      *
      */
     $plugin = Plugin_Name::get_instance();
     $this->plugin_slug = $plugin->get_plugin_slug();
     // Load admin style sheet and JavaScript.
     add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_styles'));
     add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'));
     // Add the options page and menu item.
     add_action('admin_menu', array($this, 'add_plugin_admin_menu'));
     // Add an action link pointing to the options page.
     $plugin_basename = plugin_basename(plugin_dir_path(__DIR__) . $this->plugin_slug . '.php');
     add_filter('plugin_action_links_' . $plugin_basename, array($this, 'add_action_links'));
     /*
      * Define custom functionality.
      *
      * Read more about actions and filters:
      * http://codex.wordpress.org/Plugin_API#Hooks.2C_Actions_and_Filters
      */
     add_action('@TODO', array($this, 'action_method_name'));
     add_filter('@TODO', array($this, 'filter_method_name'));
 }
 /**
  * Return an instance of this class.
  *
  * @since     1.0.0
  *
  * @return    object    A single instance of this class.
  */
 public static function get_instance()
 {
     // If the single instance hasn't been set, set it now.
     if (null == self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
 /**
  * Register callbacks for actions and filters
  *
  * @since    1.0.0.0
  */
 public function register_hook_callbacks()
 {
     register_activation_hook(Plugin_Name::get_plugin_path() . Plugin_Name::PLUGIN_ID . '.php', array($this, 'activate'));
     register_deactivation_hook(Plugin_Name::get_plugin_path() . Plugin_Name::PLUGIN_ID . '.php', array($this, 'deactivate'));
 }
 /**
  * Define the core functionality of the plugin.
  *
  * Load the dependencies, define the locale, and set the hooks for the admin area and
  * the public-facing side of the site.
  *
  * @since    1.0.0
  */
 public function __construct()
 {
     self::$plugin_path = plugin_dir_path(dirname(__FILE__));
     self::$plugin_url = plugin_dir_url(dirname(__FILE__));
     require_once self::$plugin_path . 'includes/class-' . self::PLUGIN_PREFIX . 'loader.php';
     self::$modules['Plugin_Name_Loader'] = Plugin_Name_Loader::get_instance();
     self::$modules['Plugin_Name_Controller_Public'] = Plugin_Name_Controller_Public::get_instance();
     self::$modules['Plugin_Name_Controller_Admin_Settings'] = Plugin_Name_Controller_Admin_Settings::get_instance();
     self::$modules['Plugin_Name_Controller_Admin_Notices'] = Plugin_Name_Controller_Admin_Notices::get_instance();
     Plugin_Name_Actions_Filters::init_actions_filters();
 }
 /**
  * Initialize the plugin by loading admin scripts & styles and adding a
  * settings page and menu.
  *
  * @since     1.0.0
  */
 private function __construct()
 {
     /*
      * @TODO :
      *
      * - Uncomment following lines if the admin class should only be available for super admins
      */
     /* if( ! is_super_admin() ) {
     	  return;
     	  } */
     /*
      * Call $plugin_slug from public plugin class.
      *
      * @TODO:
      *
      * - Rename "Plugin_Name" to the name of your initial plugin class
      *
      */
     $plugin = Plugin_Name::get_instance();
     $this->plugin_slug = $plugin->get_plugin_slug();
     $this->plugin_name = $plugin->get_plugin_name();
     $this->version = $plugin->get_plugin_version();
     $this->cpts = $plugin->get_cpts();
     // Load admin style sheet and JavaScript.
     add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_styles'));
     add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'));
     // Load admin style in dashboard for the At glance widget
     add_action('admin_head-index.php', array($this, 'enqueue_admin_styles'));
     // At Glance Dashboard widget for your cpts
     add_filter('dashboard_glance_items', array($this, 'cpt_dashboard_support'), 10, 1);
     // Add the options page and menu item.
     add_action('admin_menu', array($this, 'add_plugin_admin_menu'));
     //Add bubble notification for cpt pending
     add_action('admin_menu', array($this, 'pending_cpt_bubble'), 999);
     // Add an action link pointing to the options page.
     $plugin_basename = plugin_basename(plugin_dir_path(realpath(dirname(__FILE__))) . $this->plugin_slug . '.php');
     add_filter('plugin_action_links_' . $plugin_basename, array($this, 'add_action_links'));
     /*
      * CMB 2 for metabox and many other cool things!
      * https://github.com/WebDevStudios/CMB2
      * Also CMB2 Shortcode support 
      * Check on the repo for the example and documentation 
      * https://github.com/jtsternberg/Shortcode_Button
      */
     require_once plugin_dir_path(__FILE__) . '/includes/CMB2/init.php';
     require_once plugin_dir_path(__FILE__) . '/includes/CMB2-Shortcode/shortcode-button.php';
     /*
      * Add metabox
      */
     add_action('cmb2_init', array($this, 'cmb_demo_metaboxes'));
     /*
      * Define custom functionality.
      *
      * Read more about actions and filters:
      * http://codex.wordpress.org/Plugin_API#Hooks.2C_Actions_and_Filters
      */
     add_action('@TODO', array($this, 'action_method_name'));
     add_filter('@TODO', array($this, 'filter_method_name'));
     //Add the export settings method
     add_action('admin_init', array($this, 'settings_export'));
     //Add the import settings method
     add_action('admin_init', array($this, 'settings_import'));
     /*
      * Debug mode
      */
     require_once plugin_dir_path(__FILE__) . 'includes/debug.php';
     $debug = new Pn_Debug($this);
     $debug->log(__('Plugin Loaded', $this->plugin_slug));
     /*
      * Load Wp_Contextual_Help for the help tabs
      */
     add_filter('wp_contextual_help_docs_dir', array($this, 'help_docs_dir'));
     add_filter('wp_contextual_help_docs_url', array($this, 'help_docs_url'));
     if (!class_exists('WP_Contextual_Help')) {
         require_once plugin_dir_path(__FILE__) . 'includes/WP-Contextual-Help/wp-contextual-help.php';
     }
     add_action('init', array($this, 'contextual_help'));
     /*
      * Load Wp_Admin_Notice for the notices in the backend
      * 
      * First parameter the HTML, the second is the css class
      */
     if (!class_exists('WP_Admin_Notice')) {
         require_once plugin_dir_path(__FILE__) . 'includes/WP-Admin-Notice/WP_Admin_Notice.php';
     }
     new WP_Admin_Notice(__('Updated Messages'), 'updated');
     new WP_Admin_Notice(__('Error Messages'), 'error');
     /*
      * Load PointerPlus for the Wp Pointer
      * 
      * Unique paramter is the prefix
      */
     if (!class_exists('PointerPlus')) {
         require_once plugin_dir_path(__FILE__) . 'includes/PointerPlus/class-pointerplus.php';
     }
     $pointerplus = new PointerPlus(array('prefix' => $this->plugin_slug));
     //With this you can reset all the pointer with your prefix
     //$pointerplus->reset_pointer();
     add_filter('pointerplus_list', array($this, 'custom_initial_pointers'), 10, 2);
     /*
      * Load CPT_Columns
      * 
      * Check the file for example
      */
     require_once plugin_dir_path(__FILE__) . 'includes/CPT_Columns.php';
     $post_columns = new CPT_columns('demo');
     $post_columns->add_column('cmb2_field', array('label' => __('CMB2 Field'), 'type' => 'post_meta', 'meta_key' => '_demo_' . $this->plugin_slug . '_text', 'orderby' => 'meta_value', 'sortable' => true, 'prefix' => "<b>", 'suffix' => "</b>", 'def' => "Not defined", 'order' => "-1"));
 }
/**
 * Begins execution of the plugin.
 *
 * @since    1.0.0
 */
function run_plugin_name()
{
    /**
     * Check requirements and load main class
     * The main program needs to be in a separate file that only gets loaded if the plugin requirements are met.
     * Otherwise older PHP installations could crash when trying to parse it.
     **/
    if (plugin_name_requirements_met()) {
        /**
         * The core plugin class that is used to define internationalization,
         * admin-specific hooks, and public-facing site hooks.
         */
        require_once plugin_dir_path(__FILE__) . 'includes/class-plugin-name.php';
        /**
         * Begins execution of the plugin.
         *
         * Since everything within the plugin is registered via hooks,
         * then kicking off the plugin from this point in the file does
         * not affect the page life cycle.
         *
         * @since    1.0.0
         */
        $plugin = Plugin_Name::get_instance();
    } else {
        add_action('admin_notices', 'plugin_name_show_requirements_error');
        require_once ABSPATH . 'wp-admin/includes/plugin.php';
        deactivate_plugins(plugin_basename(__FILE__));
    }
}
Ejemplo n.º 22
0
 /**
  * Main PluginName Instance
  *
  * Ensures only one instance of PluginName is loaded or can be loaded.
  *
  * @todo   Replace 'Plugin_Name' with the name of your plugin class.
  * @return object self::instance The one true Plugin_Name
  * @see    Plugin_Name()
  * @access public static
  * @since  1.0.0
  */
 public static function instance()
 {
     if (is_null(self::$_instance)) {
         self::$_instance = new Plugin_Name();
         self::$_instance->setup_constants();
         self::$_instance->load_plugin_textdomain();
         self::$_instance->includes();
     }
     return self::$_instance;
 }
Ejemplo n.º 23
0
/**
 * Begins execution of the plugin.
 *
 * Since everything within the plugin is registered via hooks,
 * then kicking off the plugin from this point in the file does
 * not affect the page life cycle.
 *
 * @since    1.0.0
 */
function run_plugin_name()
{
    $plugin = new Plugin_Name();
    $plugin->run();
}
/**
 * Begins execution of the plugin.
 *
 * Since everything within the plugin is registered via hooks,
 * then kicking off the plugin from this point in the file does
 * not affect the page life cycle.
 *
 * @since    1.0.0
 */
function run_plugin_name()
{
    $plugin = new Plugin_Name();
    // Main Plugin Class
    $plugin->run();
}