2014-09-16 14:23:40 -04:00
< ? php
/**
2014-09-16 22:24:53 -04:00
* Display Featured Image for Genesis
2014-09-16 14:23:40 -04:00
*
* @package DisplayFeaturedImageGenesis
* @author Robin Cornett <hello@robincornett.com>
* @link https://github.com/robincornett/display-featured-image-genesis/
2017-02-17 09:43:46 -05:00
* @copyright 2014-2017 Robin Cornett
2014-09-16 14:23:40 -04:00
* @license GPL-2.0+
*/
/**
* Main plugin class.
*
* @package DisplayFeaturedImageGenesis
*/
class Display_Featured_Image_Genesis {
2014-10-21 18:16:00 -04:00
2016-01-12 09:13:25 -05:00
/**
* Admin area class: handles columns.
* @var Display_Featured_Image_Genesis_Admin $admin
*/
protected $admin ;
/**
* Adds new author meta.
* @var Display_Featured_Image_Genesis_Author $author
*/
protected $author ;
2016-07-02 09:17:46 -04:00
/**
* @var $customizer Display_Featured_Image_Genesis_Customizer
*/
protected $customizer ;
2016-01-12 09:13:25 -05:00
/**
* All archive description functions.
* @var Display_Featured_Image_Genesis_Description $description
*/
protected $description ;
/**
* Handles all image output functionality
* @var Display_Featured_Image_Genesis_Output $output
*/
protected $output ;
2016-04-03 15:31:17 -04:00
/**
* Updates metabox on post edit page
2016-04-04 15:50:47 -04:00
* @var Display_Featured_Image_Genesis_Post_Meta $post_meta
2016-04-03 15:31:17 -04:00
*/
2016-04-04 15:50:47 -04:00
protected $post_meta ;
2016-04-03 15:31:17 -04:00
2016-01-12 09:13:25 -05:00
/**
* Handles RSS feed output
* @var Display_Featured_Image_Genesis_RSS $rss
*/
protected $rss ;
/**
* Sets up settings page for the plugin.
* @var Display_Featured_Image_Genesis_Settings $settings
*/
protected $settings ;
/**
* Handles term meta.
* @var Display_Featured_Image_Genesis_Taxonomies $taxonomies
*/
protected $taxonomies ;
2017-11-10 13:34:30 -05:00
/**
* Register widgets and related shortcodes.
*
* @var \DisplayFeaturedImageGenesisWidgets
*/
protected $widgets ;
2016-01-12 09:13:25 -05:00
/**
* Display_Featured_Image_Genesis constructor.
*
* @param $admin
* @param $author
2016-07-02 09:17:46 -04:00
* @param $customizer
2016-01-12 09:13:25 -05:00
* @param $output
2019-05-18 15:42:08 -04:00
* @param $post_meta
2016-01-12 09:13:25 -05:00
* @param $rss
* @param $settings
* @param $taxonomies
2019-05-18 15:42:08 -04:00
* @param $widgets
2016-01-12 09:13:25 -05:00
*/
2019-05-14 14:25:46 -04:00
public function __construct ( $admin , $author , $customizer , $output , $post_meta , $rss , $settings , $taxonomies , $widgets ) {
$this -> admin = $admin ;
$this -> author = $author ;
$this -> customizer = $customizer ;
$this -> output = $output ;
$this -> post_meta = $post_meta ;
$this -> rss = $rss ;
$this -> settings = $settings ;
$this -> taxonomies = $taxonomies ;
$this -> widgets = $widgets ;
2014-09-16 14:23:40 -04:00
}
2016-01-12 09:13:25 -05:00
/**
* Main plugin function. Starts up all the things.
*/
2014-09-17 22:09:05 -04:00
public function run () {
2014-11-01 20:40:42 -04:00
if ( 'genesis' !== basename ( get_template_directory () ) ) {
2014-09-26 15:43:53 -04:00
add_action ( 'admin_init' , array ( $this , 'deactivate' ) );
2014-09-16 22:24:53 -04:00
return ;
}
2015-02-16 13:23:45 -05:00
2019-06-08 15:19:37 -04:00
require_once plugin_dir_path ( __FILE__ ) . 'helper-functions.php' ;
2014-10-21 18:16:00 -04:00
2016-07-12 09:51:22 -04:00
// Plugin setup
2015-07-26 16:21:14 -04:00
add_action ( 'after_setup_theme' , array ( $this , 'add_plugin_supports' ) );
2014-09-17 22:09:05 -04:00
add_action ( 'plugins_loaded' , array ( $this , 'load_textdomain' ) );
2015-07-12 12:26:20 -04:00
add_filter ( 'plugin_action_links_' . DISPLAYFEATUREDIMAGEGENESIS_BASENAME , array ( $this , 'add_settings_link' ) );
2016-07-02 10:25:59 -04:00
2016-07-12 09:51:22 -04:00
// Admin
add_action ( 'admin_init' , array ( $this -> admin , 'set_up_columns' ) );
add_action ( 'admin_enqueue_scripts' , array ( $this , 'enqueue_scripts' ) );
2017-11-10 13:34:30 -05:00
// Widgets
add_action ( 'widgets_init' , array ( $this -> widgets , 'register_widgets' ) );
add_action ( 'widgets_init' , array ( $this -> widgets , 'register_shortcodes' ) );
2019-06-26 13:28:19 -04:00
add_action ( 'init' , array ( $this -> widgets , 'register_blocks' ) );
2017-11-10 13:34:30 -05:00
add_action ( 'admin_enqueue_scripts' , array ( $this -> widgets , 'enqueue_scripts' ) );
2018-01-06 13:26:20 -05:00
// Taxonomies, Authors
2016-11-12 15:43:24 -05:00
add_filter ( 'displayfeaturedimagegenesis_get_taxonomies' , array ( $this -> taxonomies , 'remove_post_status_terms' ) );
2016-07-02 10:25:59 -04:00
add_action ( 'admin_init' , array ( $this -> taxonomies , 'set_taxonomy_meta' ) );
add_action ( 'admin_init' , array ( $this -> author , 'set_author_meta' ) );
2018-01-06 13:26:20 -05:00
// Post Meta
2018-11-07 17:57:25 -05:00
add_action ( 'add_meta_boxes' , array ( $this -> post_meta , 'add_metabox' ), 10 , 2 );
2016-06-21 10:51:58 -04:00
add_filter ( 'admin_post_thumbnail_html' , array ( $this -> post_meta , 'meta_box' ), 10 , 2 );
2016-04-04 15:50:47 -04:00
add_action ( 'save_post' , array ( $this -> post_meta , 'save_meta' ) );
2014-12-10 17:04:31 -05:00
2016-07-02 10:25:59 -04:00
// Settings
add_action ( 'admin_menu' , array ( $this -> settings , 'do_submenu_page' ) );
add_filter ( 'displayfeaturedimagegenesis_get_setting' , array ( $this -> settings , 'get_display_setting' ) );
// Customizer
2016-07-02 09:17:46 -04:00
add_action ( 'customize_register' , array ( $this -> customizer , 'customizer' ) );
2016-07-02 10:25:59 -04:00
// Front End Output
add_action ( 'get_header' , array ( $this -> output , 'manage_output' ) );
add_filter ( 'genesis_get_image_default_args' , array ( $this -> output , 'change_thumbnail_fallback' ) );
// RSS
add_action ( 'template_redirect' , array ( $this -> rss , 'maybe_do_feed' ) );
2014-09-16 14:23:40 -04:00
}
2014-09-26 15:43:53 -04:00
/**
* deactivates the plugin if Genesis isn't running
*
* @since 1.1.2
*
*/
public function deactivate () {
2015-07-12 12:26:20 -04:00
deactivate_plugins ( DISPLAYFEATUREDIMAGEGENESIS_BASENAME );
add_action ( 'admin_notices' , array ( $this , 'error_message' ) );
2014-09-26 15:43:53 -04:00
}
2014-09-16 14:23:40 -04:00
/**
2014-09-17 22:09:05 -04:00
* Error message if we're not using the Genesis Framework.
2014-09-16 14:23:40 -04:00
*
2014-09-17 22:09:05 -04:00
* @since 1.1.0
2014-09-16 14:23:40 -04:00
*/
2014-09-17 22:09:05 -04:00
public function error_message () {
2014-11-11 13:16:11 -05:00
2015-04-24 17:02:47 -04:00
$error = sprintf ( __ ( 'Sorry, Display Featured Image for Genesis works only with the Genesis Framework. It has been deactivated.' , 'display-featured-image-genesis' ) );
2014-11-11 13:16:11 -05:00
2017-11-21 08:57:40 -05:00
if ( version_compare ( PHP_VERSION , '5.6' , '<' ) ) {
2014-11-11 13:16:11 -05:00
$error = $error . sprintf (
2017-11-21 08:57:40 -05:00
/* translators: placeholder is the user's PHP version. */
2014-11-11 13:16:11 -05:00
__ ( ' But since we\'re talking anyway, did you know that your server is running PHP version %1$s, which is outdated? You should ask your host to update that for you.' , 'display-featured-image-genesis' ),
2014-09-26 15:43:53 -04:00
PHP_VERSION
2014-11-11 13:16:11 -05:00
);
2014-09-26 15:43:53 -04:00
}
2015-04-24 17:02:47 -04:00
echo '<div class="error"><p>' . esc_attr ( $error ) . '</p></div>' ;
2014-11-11 13:16:11 -05:00
2014-09-26 15:43:53 -04:00
if ( isset ( $_GET [ 'activate' ] ) ) {
unset ( $_GET [ 'activate' ] );
}
2014-09-16 14:23:40 -04:00
}
2014-11-01 20:07:53 -04:00
/**
* add plugin support for new image size and excerpts on pages, if move excerpts option is enabled
*
* @since 1.3.0
*/
2015-07-26 16:21:14 -04:00
public function add_plugin_supports () {
2014-11-01 20:07:53 -04:00
2019-10-22 17:29:46 -04:00
if ( ! has_image_size ( '2048x2048' ) ) {
$args = apply_filters (
'displayfeaturedimagegenesis_custom_image_size' ,
array (
'width' => 2000 ,
'height' => 2000 ,
'crop' => false ,
)
);
add_image_size ( 'displayfeaturedimage_backstretch' , ( int ) $args [ 'width' ], ( int ) $args [ 'height' ], ( bool ) $args [ 'crop' ] );
}
2016-02-23 13:27:02 -05:00
2019-05-13 14:05:15 -04:00
$move_excerpts = displayfeaturedimagegenesis_get_setting ( 'move_excerpts' );
if ( $move_excerpts ) {
2014-11-01 20:07:53 -04:00
add_post_type_support ( 'page' , 'excerpt' );
}
}
2014-09-16 14:23:40 -04:00
/**
2014-09-17 22:09:05 -04:00
* Set up text domain for translations
2014-09-16 14:23:40 -04:00
*
2014-09-17 22:09:05 -04:00
* @since 1.1.0
2014-09-16 14:23:40 -04:00
*/
2014-09-17 22:09:05 -04:00
public function load_textdomain () {
2017-05-18 16:36:27 -04:00
load_plugin_textdomain ( 'display-featured-image-genesis' );
2014-09-16 14:23:40 -04:00
}
2014-12-30 16:36:33 -05:00
/**
* enqueue admin scripts
*
* @since 1.2.1
*/
public function enqueue_scripts () {
2015-01-03 15:42:20 -05:00
2019-05-14 14:25:46 -04:00
$version = displayfeaturedimagegenesis_get () -> version ;
2019-05-13 10:26:50 -04:00
$minify = defined ( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min' ;
2014-12-30 16:36:33 -05:00
2019-05-13 10:26:50 -04:00
wp_register_script ( 'displayfeaturedimage-upload' , plugins_url ( " /includes/js/settings-upload { $minify } .js " , dirname ( __FILE__ ) ), array ( 'jquery' , 'media-upload' , 'thickbox' ), $version , true );
2019-05-13 10:30:54 -04:00
wp_register_script ( 'widget_selector' , plugins_url ( " /includes/js/widget-selector { $minify } .js " , dirname ( __FILE__ ) ), array ( 'jquery' ), $version , true );
2014-12-30 16:36:33 -05:00
2015-11-17 14:03:21 -05:00
$screen = get_current_screen ();
$screen_ids = array (
'appearance_page_displayfeaturedimagegenesis' ,
'profile' ,
2015-11-17 16:36:15 -05:00
'user-edit' ,
2015-11-17 14:03:21 -05:00
);
2015-11-17 16:36:15 -05:00
if ( in_array ( $screen -> id , $screen_ids , true ) || ! empty ( $screen -> taxonomy ) ) {
2014-12-30 16:36:33 -05:00
wp_enqueue_media ();
wp_enqueue_script ( 'displayfeaturedimage-upload' );
2019-05-13 10:26:50 -04:00
wp_localize_script (
'displayfeaturedimage-upload' ,
'DisplayFeaturedImageGenesis' ,
array (
'text' => __ ( 'Select Image' , 'display-featured-image-genesis' ),
)
);
2015-01-03 15:42:20 -05:00
}
2015-01-05 17:54:56 -05:00
}
2015-07-12 12:28:21 -04:00
/**
* Add link to plugin settings page in plugin table
2017-05-18 16:36:27 -04:00
* @param $links array link to settings page
* @return array
2015-07-12 12:28:21 -04:00
*
* @since 2.3.0
*/
public function add_settings_link ( $links ) {
$links [] = sprintf ( '<a href="%s">%s</a>' , esc_url ( admin_url ( 'themes.php?page=displayfeaturedimagegenesis' ) ), esc_attr__ ( 'Settings' , 'display-featured-image-genesis' ) );
return $links ;
}
2014-09-16 14:23:40 -04:00
}