define_constants();
// Required class file include.
spl_autoload_register( array( $this, 'autoload' ) );
// Include required files.
$this->includes();
// instantiate classes.
$this->instantiate();
// Initialize the filter hooks.
$this->init_filters();
// Initialize the action hooks.
$this->init_actions();
}
/**
* Initialize WordPress filter hooks
*
* @return void
*/
function init_filters() {
add_filter( 'plugin_action_links', array( $this, 'add_plugin_action_links' ), 10, 2 );
add_filter( 'manage_sp_pc_shortcodes_posts_columns', array( $this, 'add_shortcode_column' ) );
add_filter( 'plugin_row_meta', array( $this, 'after_post_carousel_row_meta' ), 10, 4 );
}
/**
* Initialize WordPress action hooks
*
* @return void
*/
function init_actions() {
add_action( 'plugins_loaded', array( $this, 'load_text_domain' ) );
add_action( 'manage_sp_pc_shortcodes_posts_custom_column', array( $this, 'add_shortcode_form' ), 10, 2 );
add_action( 'activated_plugin', array( $this, 'redirect_help_page' ) );
}
/**
* Define constants
*
* @since 2.1
*/
public function define_constants() {
$this->define( 'SP_PC_VERSION', $this->version );
$this->define( 'SP_PC_PATH', plugin_dir_path( __FILE__ ) );
$this->define( 'SP_PC_URL', plugin_dir_url( __FILE__ ) );
$this->define( 'SP_PC_BASENAME', plugin_basename( __FILE__ ) );
}
/**
* Define constant if not already set
*
* @since 2.1
*
* @param string $name
* @param string|bool $value
*/
public function define( $name, $value ) {
if ( ! defined( $name ) ) {
define( $name, $value );
}
}
/**
* Load TextDomain for plugin.
*
* @since 2.1
*/
public function load_text_domain() {
load_plugin_textdomain( 'post-carousel', false, SP_PC_PATH . '/languages' );
}
/**
* Add plugin action menu
*
* @param array $links
* @param string $file
*
* @return array
*/
public function add_plugin_action_links( $links, $file ) {
if ( $file == SP_PC_BASENAME ) {
$new_links = array(
sprintf( '%s', 'https://shapedplugin.com/plugin/post-carousel-pro', 'color:red;font-weight:bold', __( 'Go Pro!', 'post-carousel' ) ),
sprintf( '%s', admin_url( 'edit.php?post_type=sp_pc_shortcodes' ), __( 'Shortcode Generator', 'post-carousel' ) ),
);
return array_merge( $new_links, $links );
}
return $links;
}
/**
* Add plugin row meta link
*
* @since 2.1
*
* @param $plugin_meta
* @param $file
*
* @return array
*/
function after_post_carousel_row_meta( $plugin_meta, $file ) {
if ( $file == SP_PC_BASENAME ) {
$plugin_meta[] = '' . __( 'Live Demo', 'post-carousel' ) . '';
}
return $plugin_meta;
}
/**
* Autoload class files on demand
*
* @param string $class requested class name
*/
function autoload( $class ) {
$name = explode( '_', $class );
if ( isset( $name[2] ) ) {
$class_name = strtolower( $name[2] );
$filename = SP_PC_PATH . '/class/' . $class_name . '.php';
if ( file_exists( $filename ) ) {
require_once $filename;
}
}
}
/**
* Instantiate all the required classes
*
* @since 2.1
*/
function instantiate() {
$this->metabox = SP_PC_MetaBox::getInstance();
$this->shortcode = SP_PC_ShortCodes::getInstance();
do_action( 'sp_pc_instantiate', $this );
}
/**
* page router instantiate
*
* @since 2.1
*/
function page() {
$this->router = SP_PC_Router::instance();
return $this->router;
}
/**
* Include the required files
*
* @return void
*/
function includes() {
$this->page()->sp_pc_function();
$this->router->includes();
}
/**
* ShortCode Column
*
* @param $columns
*
* @return array
*/
function add_shortcode_column() {
$new_columns['cb'] = '';
$new_columns['title'] = __( 'Carousel Title', 'post-carousel' );
$new_columns['shortcode'] = __( 'Shortcode', 'post-carousel' );
$new_columns[''] = '';
$new_columns['date'] = __( 'Date', 'post-carousel' );
return $new_columns;
}
/**
* @param $column
* @param $post_id
*/
function add_shortcode_form( $column, $post_id ) {
switch ( $column ) {
case 'shortcode':
$column_field = '';
echo $column_field;
break;
default:
break;
} // end switch
}
/**
* Redirect after active
*
* @param $plugin
*/
function redirect_help_page( $plugin ) {
if ( $plugin == SP_PC_BASENAME ) {
exit( wp_redirect( admin_url( 'edit.php?post_type=sp_pc_shortcodes&page=help' ) ) );
}
}
}
}
/**
* Returns the main instance.
*
* @since 2.1
* @return SP_Post_Carousel
*/
function sp_post_carousel() {
return SP_Post_Carousel::instance();
}
// sp_post_carousel instance.
sp_post_carousel();