__FILE__ = $__FILE__; } return static::get_instance(); } /** * Returns the plugin's object instance. * * @return object The plugin object instance. */ public static function get_instance() { if ( isset( static::$instance ) ) { return static::$instance; } } /** * Add a WordPress hook (action/filter). * * @param mixed $hook,... first parameter is the name of the hook. * If second or third parameters are included, * they will be used as a priority (if an integer) * or as a class method callback name (if a string). * * @return bool Always returns true. */ public function hook( $hook ) { $priority = 10; $method = $this->sanitize_method( $hook ); $args = func_get_args(); unset( $args[0] ); foreach ( (array) $args as $arg ) { if ( is_int( $arg ) ) { $priority = $arg; } else { $method = $arg; } } return add_action( $hook, array( $this, $method ), $priority, 999 ); } /** * Remove a WordPress hook (action/filter). * * @param mixed $hook,... first parameter is the name of the hook. * If second or third parameters are included, * they will be used as a priority (if an integer) * or as a class method callback name (if a string). * * @return bool Always returns true. */ public function unhook( $hook ) { $priority = 10; $method = $this->sanitize_method( $hook ); $args = func_get_args(); unset( $args[0] ); foreach ( (array) $args as $arg ) { if ( is_int( $arg ) ) { $priority = $arg; } else { $method = $arg; } } return remove_action( $hook, array( $this, $method ), $priority ); } /** * Sanitize a method name by replacing dots and dashes. * * @param string $method The method name to sanitize. * * @return string The sanitized method name. */ private function sanitize_method( $method ) { return str_replace( array( '.', '-' ), array( '_DOT_', '_DASH_' ), $method ); } /** * Includes a file (relative to the plugin base path) * and optionally globalizes a named array passed in * * @param string $file the file to include * @param array $data a named array of data to globalize */ protected function include_file( $file, $data = array() ) { extract( $data, EXTR_SKIP ); include( $this->get_path() . $file ); } /** * Returns the URL to the plugin directory * * @return string The URL to the plugin directory. */ public function get_url() { return plugin_dir_url( $this->__FILE__ ); } /** * Returns the path to the plugin directory. * * @return string The absolute path to the plugin directory. */ public function get_path() { return plugin_dir_path( $this->__FILE__ ); } /** * @param string $domain The plugin textdomain. * @param string $path Relative path to the `languages` folder. * * @return bool Returns true if the textdomain was loaded successfully, false otherwise. */ public function load_textdomain( $domain, $path ) { return load_plugin_textdomain( $domain, false, basename( dirname( $this->__FILE__ ) ) . $path ); } } }