Esempio n. 1
0
 /**
  * Create an instance of WPDK class and init the franework
  *
  * @return WPDK
  */
 private function __construct()
 {
     // First of all, load SPL autoload logic
     $this->_wpdkClassLoadingPath = array();
     spl_autoload_extensions('.php');
     // for faster execution
     spl_autoload_register(array($this, 'autoloadWPDKEnvironment'));
     // Load the framework in SPL autoload logic
     $this->defines();
     $this->registerClasses();
     // WPDK Cron schedules
     WPDKCronSchedules::init();
     // Fires to flush (clear) the third parties plugins.
     add_action('wpdk_flush_cache_third_parties_plugins', array($this, 'wpdk_flush_cache_third_parties_plugins'));
     // Load the translation of WPDK
     add_action('init', array($this, 'load_plugin_textdomain'));
     // Register scripts and styles
     add_action('init', array('WPDKUIComponents', 'init'));
     // Placeholder metabox
     add_action('init', array('WPDKPostPlaceholders', 'init'));
     // Users enhancer
     add_action('set_current_user', array('WPDKUsers', 'init'));
     // Shortcodes
     add_action('wp_loaded', array('WPDKServiceShortcodes', 'init'));
     // Ajax
     if (wpdk_is_ajax()) {
         add_action('wp_loaded', array('WPDKServiceAjax', 'init'));
     }
     // Fires when scripts are printed for all admin pages.
     add_action('admin_print_scripts', array($this, 'admin_print_scripts'), 1);
     // Print scripts or data in the head tag on the front end.
     add_action('wp_head', array($this, 'wp_head'), 1);
     /**
      * Fires when WPDK is loaded.
      */
     do_action('WPDK');
 }
Esempio n. 2
0
<?php

if (wpdk_is_ajax()) {
    /**
     * Ajax class for extends an Ajax parent class.
     * You will use this class to extends a your own Ajax gateway class.
     *
     *     class YourClass extends WPDKAjax {
     *       public function actions()
     *       {
     *         return array();
     *       }
     *     }
     *
     * In this way you can access to `registerActions` method
     *
     * @class              WPDKAjax
     * @author             =undo= <*****@*****.**>
     * @copyright          Copyright (C) 2012-2013 wpXtreme Inc. All Rights Reserved.
     * @date               2013-11-15
     * @version            1.0.3
     * @since              0.7.5
     */
    class WPDKAjax
    {
        /**
         * Create an instance of WPDKAjax class
         *
         * @brief Construct
         *
         * @return WPDKAjax
Esempio n. 3
0
 /**
  * This action is used to avoid display the admin backend area to subscriber user
  *
  * @brief Avoid admin
  */
 public function admin_init()
 {
     if (wpdk_is_ajax()) {
         return;
     }
     if (!is_user_logged_in()) {
         return;
     }
     /* Check for roles */
     if (!empty($this->setup->disable_admin_for_roles)) {
         // Not implement
     }
     /* Check for capabilies */
     if (!empty($this->setup->disable_admin_if_user_has_not_caps)) {
         $pass = false;
         $roles = $this->setup->disable_admin_if_user_has_not_caps;
         if (!empty($roles) && is_array($roles)) {
             foreach ($roles as $role) {
                 if ($pass = current_user_can($role)) {
                     break;
                 }
             }
         } elseif (!empty($roles) && is_string($roles)) {
             $pass = current_user_can($roles);
         }
         if (!$pass) {
             die;
         }
     }
 }
 /**
  * Get the current action selected from the bulk actions dropdown.
  *
  * @brief Current action
  *
  * @param string $nonce Optional. Force nonce verify
  *
  * @return string|bool The action name or False if no action was selected
  */
 public function current_action($nonce = '')
 {
     // Ajax
     if (wpdk_is_ajax()) {
         return false;
     }
     // Action
     $action = false;
     if (isset($_REQUEST['action']) && -1 != $_REQUEST['action']) {
         $action = $_REQUEST['action'];
     } elseif (isset($_REQUEST['action2']) && -1 != $_REQUEST['action2']) {
         $action = $_REQUEST['action2'];
     }
     // Nonce
     if (!empty($nonce) && !empty($action) && isset($_REQUEST['_wpnonce'])) {
         if (wp_verify_nonce($_REQUEST['_wpnonce'], 'bulk-' . $nonce)) {
             return $action;
         }
     }
     return $action;
 }
Esempio n. 5
0
 /**
  * Return the preferences object from the option. If not exists then an object is create runtime for you.
  * This is a utility method but you have to override if you don't like insert name and class name parameters. In
  * you own class just use:
  *
  *     public static function init() {
  *       return parent::init( self::PREFERENCES_NAME, __CLASS__ );
  *     }
  *
  * Or, if you like check the prefernces version
  *
  *     public static function init() {
  *       return parent::init( self::PREFERENCES_NAME, __CLASS__, LAST_VERSION );
  *     }
  *
  * If you wish store preferences for each user use:
  *
  *     public static function init() {
  *       $user_id = get_current_user_id();
  *       return parent::init( self::PREFERENCES_NAME, __CLASS__, LAST_VERSION, $user_id );
  *     }
  *
  * @params string      $name       A string used as name for options. Make it unique more possible.
  * @params string      $class_name The subclass class name
  * @params bool|string $version    Optional. Version compare
  * @params bool|int    $user_id    Optional. User ID
  *
  * @return WPDKPreferences
  */
 public static function init()
 {
     /*
      * since 1.5.1
      * try to avoid 'PHP Strict Standards:  Declaration of ::init() should be compatible with WPDKPreferences::init'
      *
      * Remeber that if a params is missing it is NULL
      */
     $args = func_get_args();
     list($name, $class_name) = $args;
     $version = isset($args[2]) ? $args[2] : false;
     $user_id = isset($args[3]) ? $args[3] : false;
     static $instance = array();
     static $busy = false;
     /**
      * @var WPDKPreferences $preferences
      */
     $preferences = null;
     // Sanitize name
     $name = sanitize_title($name);
     // Flag to store
     $do_update = false;
     // Check if static
     if (isset($instance[$name])) {
         $preferences = $instance[$name];
     } else {
         $preferences = empty($user_id) ? get_option($name) : get_user_meta($user_id, $name, true);
         $do_update = true;
     }
     if (!is_object($preferences) || !is_a($preferences, $class_name)) {
         $init = create_function('$name,$user_id', 'return new ' . $class_name . '( $name, $user_id );');
         $preferences = $init($name, $user_id);
         // Do update?
         if ($do_update) {
             $preferences->update();
         }
     }
     if (!empty($version)) {
         // Or if the onfly version is different from stored version
         if (version_compare($preferences->version, $version) < 0) {
             // For i.e. you would like update the version property
             $preferences->version = $version;
             $preferences->update();
         }
     }
     // Check for post data and no ajax
     if (!isset($instance[$name]) && !wpdk_is_ajax()) {
         // Get preferences class name
         $preferences_class = isset($_POST['wpdk_preferences_class']) ? $_POST['wpdk_preferences_class'] : false;
         // Is it this preferences ?
         if (false === $busy && !empty($preferences_class) && $preferences_class == get_class($preferences)) {
             // Avoid twice
             $busy = true;
             // Get branch
             $branch = isset($_POST['wpdk_preferences_branch']) ? $_POST['wpdk_preferences_branch'] : false;
             if (!empty($branch)) {
                 // Actions
                 $reset_to_default = isset($_POST['reset-to-default-preferences']);
                 $update_preferences = isset($_POST['update-preferences']);
                 // Reset to default a specified branch
                 if ($reset_to_default) {
                     // Fires before display the view. You can add your custome feedback message.
                     add_action('wpdk_preferences_feedback-' . $branch, array($preferences, 'wpdk_preferences_feedback_reset'));
                     $preferences->{$branch}->defaults();
                     $preferences->update();
                     /**
                      * Fires when preferences branch are reset to default.
                      *
                      * TODO This action is incomplete due missing preferences name. We could have more brabch with the same name!!!
                      *
                      * @since 1.7.3
                      *
                      * @param WPDKPreferencesBranch $branch An instance of WPDKPreferencesBranch class.
                      */
                     do_action('wpdk_preferences_reset_to_default_branch-' . $branch, $preferences->{$branch});
                 } elseif ($update_preferences) {
                     // TODO Replace (asap) with
                     //do_action( 'wpdk_flush_cache_third_parties_plugins' );
                     // Since 1.5.2 - WP SuperCache patch
                     if (function_exists('wp_cache_clear_cache')) {
                         wp_cache_clear_cache();
                     }
                     // Since 1.5.16 - W3 Total Cache Plugin
                     if (function_exists('w3tc_pgcache_flush')) {
                         w3tc_pgcache_flush();
                     }
                     add_action('wpdk_preferences_feedback-' . $branch, array($preferences, 'wpdk_preferences_feedback_update'));
                     $preferences->{$branch}->update();
                     $preferences->update();
                     /**
                      * Fires when preferences branch are updated.
                      *
                      * @since 1.7.3
                      *
                      * @param WPDKPreferencesBranch $branch An instance of WPDKPreferencesBranch class.
                      */
                     do_action('wpdk_preferences_update_branch-' . $branch, $preferences->{$branch});
                 }
             } elseif (isset($_POST['wpdk_preferences_reset_all'])) {
                 $preferences->defaults();
                 $preferences->update();
             } elseif (isset($_POST['wpdk_preferences_repair'])) {
                 $preferences->delta();
             } else {
                 $preferences = WPDKPreferencesImportExport::init($preferences);
             }
         }
         $busy = false;
     }
     $instance[$name] = $preferences;
     return $instance[$name];
 }
Esempio n. 6
0
 /**
  * Create a WPDKWordPressPlugin instance
  *
  * @brief Construct
  *
  * @param string $file Usually you set it as `__FILE__`, which is the name of main file of plugin
  *
  * @return WPDKWordPressPlugin
  */
 public function __construct($file = null)
 {
     parent::__construct($file);
     /*
      * Load SPL autoload logic for this instance
      * NOTE: any WPX plugin has its own SPL autoload logic
      *
      */
     $this->_wpxPluginsClassesLoadingPath = array();
     spl_autoload_extensions('.php');
     // for faster execution
     spl_autoload_register(array($this, 'autoloadEnvironment'));
     // Path unix
     $this->path = trailingslashit(dirname($file));
     $this->classesPath = $this->path . 'classes/';
     $this->databasePath = $this->path . 'database/';
     // URL
     $this->url = trailingslashit(plugin_dir_url($file));
     $this->assetsURL = $this->url . 'assets/';
     $this->cssURL = $this->assetsURL . 'css/';
     $this->imagesURL = $this->cssURL . 'images/';
     $this->javascriptURL = $this->assetsURL . 'js/';
     // Only folder name
     $this->folderName = trailingslashit(basename(dirname($file)));
     // WordPress slug plugin, Eg. wpx-smartshop/main.php
     $this->pluginBasename = plugin_basename($file);
     // Built-in slug
     $this->slug = sanitize_title($this->name);
     // Useful property
     $this->protocol = self::protocol();
     $this->urlAjax = self::urlAjax();
     // Load text domain
     load_plugin_textdomain($this->textDomain, false, $this->textDomainPath);
     // Preferences
     add_action('init', array($this, 'preferences'));
     // Ajax
     if (wpdk_is_ajax()) {
         add_action('init', array($this, 'ajax'));
     }
     // Admin backend area
     if (is_admin()) {
         add_action('init', array($this, 'admin'));
         add_action('admin_init', array($this, 'admin_init'));
     } elseif (!isset($GLOBALS['pagenow']) || isset($GLOBALS['pagenow']) && !in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'))) {
         add_action('init', array($this, 'theme'));
     }
     // Activation & Deactivation Hook
     register_activation_hook($file, array($this, 'activation'));
     register_deactivation_hook($file, array($this, 'deactivation'));
     /*
      * There are many pitfalls to using the uninstall hook. It ’ s a much cleaner, and easier, process to use the
      * uninstall.php method for removing plugin settings and options when a plugin is deleted in WordPress.
      *
      * Using uninstall.php file. This is typically the preferred method because it keeps all your uninstall code in a
      * separate file. To use this method, create an uninstall.php file and place it in the root directory of your
      * plugin. If this file exists WordPress executes its contents when the plugin is deleted from the WordPress
      * Plugins screen page.
      *
      */
     // register_uninstall_hook( $file, array( $this, 'uninstall' ) );
     // Fires after all default WordPress widgets have been registered.
     add_action('widgets_init', array($this, 'widgets'));
 }