plugin_file_name_path = $plugin_file_path; $this->plugin_dir_path = plugin_dir_path( $this->plugin_file_name_path ); $this->plugin_dir_url = plugin_dir_url( $this->plugin_file_name_path ); $plugin_data = get_file_data( $this->plugin_file_name_path, array( 'Version' => 'Version' ), 'plugin' ); $this->version = $plugin_data['Version'] ?? '1.0'; } /** * Returns base plugin name based on it's main Namespace - useful for localize script variable names. * * @return string */ public static function get_short_name() { $namespace_parts = explode( '\\', static::class ); return $namespace_parts[0] . $namespace_parts[1] ?? ''; } /** * Singleton instance getter. * It requires __FILE__ path of plugin passed in upon initial instantiation. * If you need to get already initialized at plugins loaded stage instance, just ommit this param, it will be ignored anyway. * * @param string $plugin_file_path File path of plugin. * @param Plugin $master_plugin Reference to master plugin to be accessible inside child plugin, for ease of access. * * @return static */ public static function get_instance( $plugin_file_path = '', $master_plugin = null ) { if ( is_null( static::$instance ) ) { if ( empty( $plugin_file_path ) ) { _doing_it_wrong( esc_attr( static::class ), 'Class ' . esc_attr( static::class ) . ' should be instantiated through get_instance( __FILE__ )', 1 ); } static::$instance = new static( $plugin_file_path, $master_plugin ); } return static::$instance; } }