/home/fdhrevqn/public_html/wp-content/themes/fox/inc/admin/admin.php
<?php
if ( ! class_exists( 'Fox_Admin' ) ) :
/**
* Admin Class
*
* @since Fox 2.2
* @improved from Fox 4.0
*/
class Fox_Admin {
/**
*
*/
public function __construct() {
}
/**
* The one instance of Fox_Admin
*
* @since Fox 2.2
*/
private static $instance;
/**
* Instantiate or return the one Fox_Admin instance
*
* @since Fox 2.2
* @return Fox_Admin
*/
public static function instance() {
if ( is_null( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Initiate the class
* contains action & filters
*
* @since Fox 2.2
*/
public function init() {
/**
* 01 - INTERFACE
*/
// since 4.0
add_action( 'admin_menu', array( $this, 'admin_menu' ), 0 );
add_filter( 'admin_footer_text', [ $this, 'admin_footer_text' ] );
/**
* Add a thumbnail column in edit.php
* Thank to: http://wordpress.org/support/topic/adding-custum-post-type-thumbnail-to-the-edit-screen
* @since 1.0
*/
add_action( 'manage_posts_custom_column', array( $this, 'add_thumbnail_value_editscreen' ), 10, 2 );
add_filter( 'manage_edit-post_columns', array( $this, 'columns_filter' ) , 10, 1 );
add_filter( 'manage_edit-category_columns', [ $this, 'edit_term_columns' ], 10, 3 );
add_filter( 'manage_category_custom_column', [ $this, 'manage_term_custom_column' ], 10, 3 );
add_filter( 'manage_edit-post_tag_columns', [ $this, 'edit_term_columns' ], 10, 3 );
add_filter( 'manage_post_tag_custom_column', [ $this, 'manage_term_custom_column' ], 10, 3 );
/**
* 02 - FRAMEWORK
*/
// metabox framework
require_once FOX_ADMIN_PATH . 'framework/metabox.php';
require_once FOX_ADMIN_PATH . 'framework/tax-metabox.php';
// widgets
require_once FOX_ADMIN_PATH . 'framework/widget.php';
// TGM
require_once FOX_ADMIN_PATH . 'framework/tgm.php';
/**
* 03 - FUNCTIONALITY
*/
// register plugins needed for theme
add_action( 'tgmpa_register', array ( $this, 'register_required_plugins' ) );
// Include media upload to sidebar area
// This will be used when we need to upload something
add_action( 'sidebar_admin_setup', array( $this, 'wp_enqueue_media' ) );
// nav custom fields
require_once get_template_directory() . '/inc/admin/framework/nav-custom-fields.php';
// enqueue scripts
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
// localization
add_action( 'wiadminjs', array( $this, 'l10n' ) );
// metabox
add_filter( 'fox_metaboxes', array( $this, 'metaboxes' ) );
add_filter( 'fox_term_metaboxes', array( $this, 'term_metaboxes' ) );
}
/**
* Admin Menu
* @since 4.0
* ------------------------------------------------------------ */
function admin_menu() {
// add admin page to Appearance
$hook = add_menu_page(
// title name
'Welcome to The Fox',
// menu name
'Fox Magazine',
// role
'manage_options',
// slug
'fox',
// function
array( $this, 'create_admin_page'),
// icon
// 'dashicons-admin-site-alt3',
// FOX_ADMIN_URL . 'images/fox.png',
'dashicons-fox',
// priority
2
);
$hook = add_submenu_page(
'fox',
'Theme Options',
'Theme Options',
'manage_options',
'fox-theme-options',
array( $this, 'create_theme_options_page')
);
}
/**
* Welcome page
* @since 4.0
* ------------------------------------------------------------ */
function create_admin_page() {
include_once FOX_ADMIN_PATH . 'welcome.php';
}
/**
* theme options more clear
* @since 4.4
* ------------------------------------------------------------ */
function create_theme_options_page() {
?>
<div class="wrap about-wrap">
<h1>Theme Options</h1>
<p>Fox uses the native WordPress Customizer which can be found under <strong>Appearance > Customize</strong></p>
<img src="<?php echo get_template_directory_uri() . '/inc/admin/images/customizer.jpg'; ?>" alt="Customizer" width="500" style="width:500px; background: white; padding: 10px; border: 1px solid #e0e0e0" />
</div>
<?php
}
/**
* Admin Footer Text
* @since 4.0
* ------------------------------------------------------------ */
function admin_footer_text( $text ) {
$screen = get_current_screen();
if ( $screen->parent_base == 'fox' ) {
$text = 'Enjoyed <strong>The Fox Magazine</strong>? Help us by <a href="https://themeforest.net/item/the-fox-contemporary-magazine-theme-for-creators/reviews/11103012" target="_blank">leave a 5-star rating</a>. We really appreciate your support!';
}
return $text;
}
/**
* Render thumbnail for post
* @since 4.0
* ------------------------------------------------------------ */
function add_thumbnail_value_editscreen( $column_name, $post_id ) {
$width = (int) 50;
$height = (int) 50;
if ( 'thumbnail' == $column_name ) {
// thumbnail of WP 2.9
$thumbnail = get_post_meta( $post_id, '_thumbnail_id', true );
if ( $thumbnail ) {
$thumbnail = wp_get_attachment_image( $thumbnail, [ 50, 50 ] );
}
if ( ! $thumbnail ) {
$thumbnail = '<img src="' . get_template_directory_uri() . '/images/placeholder.png' . '" atl="No thumbnail" width="50" />';
}
$format = get_post_format( $post_id );
$format_indicator = '';
if ( $format ) {
$format_indicator = '<i class="dashicons dashicons-format-' . $format . '"></i>';
}
echo '<div class="fox-column-thumbnail">' . $thumbnail . $format_indicator . '</div>';
}
}
/**
* Add Thumbnail column to post
* @since 4.0
* ------------------------------------------------------------ */
function columns_filter( $columns ) {
$column_thumbnail = array( 'thumbnail' => 'Thumbnail' );
$columns = array_slice( $columns, 0, 1, true ) + $column_thumbnail + array_slice( $columns, 1, NULL, true );
return $columns;
}
/**
* Add Thumbnail column to category/tag
* @since 4.0
* ------------------------------------------------------------ */
function edit_term_columns( $columns ) {
$columns = array_merge( [ 'term_featured_image' => 'Thumbnail' ], $columns );
return $columns;
}
/**
* Render Thumbnail category/tag
* @since 4.0
* ------------------------------------------------------------ */
function manage_term_custom_column( $out, $column, $term_id ) {
if ( 'term_featured_image' === $column ) {
$thumbnail = get_term_meta( $term_id, '_wi_thumbnail', true );
if ( $thumbnail ) {
$thumbnail = wp_get_attachment_image( $thumbnail, [ 80, 80 ] );
}
if ( ! $thumbnail ) $thumbnail = '<img src="' . get_template_directory_uri() . '/images/placeholder.png' . '" atl="No thumbnail" width="80" />';
$out = sprintf( '<div class="term-meta-thumbnail">%s</div>', $thumbnail );
}
return $out;
}
/**
* Register Plugins
* @since 1.0
* ------------------------------------------------------------ */
function register_required_plugins (){
$url = 'https://foxdata.withemes.com/wp-content/uploads/versions.txt';
$url2 = 'https://thefox-demo.s3.amazonaws.com/versions.txt';
$cache_time = DAY_IN_SECONDS;
$key = 'fox_plugin_versions';
$body = get_transient( $key );
if ( false === $body ) {
$response = wp_remote_get( $url );
if ( is_wp_error( $response ) ) {
$response = wp_remote_get( $url2 );
}
if ( ! is_wp_error( $response ) ) {
$body = wp_remote_retrieve_body( $response );
$json = json_decode( $body, true );
if ( ! empty( $json ) ) {
set_transient( $key , $body, $cache_time );
}
}
} else {
$json = json_decode( $body, true );
}
$json = wp_parse_args( $json, [
'fox-framework' => '1.4',
'fox-post-views-counter' => '1.0.2',
'envato-market' => '2.0.6',
]);
$plugin_info = [
'fox-framework' => '(Fox) Elementor Addons',
'fox-post-views-counter' => '(Fox) Post Views Counter',
'envato-market' => 'Envato Market',
];
$plugin_arr = [];
$plugin_arr = array (
array(
'name' => 'Contact Form 7', // The plugin name
'slug' => 'contact-form-7', // The plugin slug (typically the folder name)
'required' => false, // If false, the plugin is only 'recommended' instead of required
),
// recommended since 4.3
array(
'name' => 'Instagram Feed',
'slug' => 'instagram-feed',
'required' => false,
),
array(
'name' => 'Mailchimp for WP',
'slug' => 'mailchimp-for-wp',
'required' => false,
'message' => false,
),
array(
'name' => 'Elementor Page Builder', // The plugin name
'slug' => 'elementor', // The plugin slug (typically the folder name)
'required' => false, // If false, the plugin is only 'recommended' instead of required
'message' => false,
),
array(
'name' => 'WooCommerce', // The plugin name
'slug' => 'woocommerce', // The plugin slug (typically the folder name)
'required' => false, // If false, the plugin is only 'recommended' instead of required
'message' => false,
),
array(
'name' => 'Co-Authors Plus', // The plugin name
'slug' => 'co-authors-plus', // The plugin slug (typically the folder name)
'required' => false, // If false, the plugin is only 'recommended' instead of required
'message' => false,
),
/*
array(
'name' => 'One Click Demo Import',
'slug' => 'one-click-demo-import',
'force_deactivation' => true,
)
*/
);
foreach ( $json as $plugin_slug => $plugin_data ) {
$plug = [];
$plug[ 'name' ] = $plugin_info[ $plugin_slug ];
// ie. this is the version of plugin
if ( is_string( $plugin_data ) ) {
$plug[ 'version' ] = $plugin_data;
$plug[ 'source' ] = 'https://thefox-demo.s3.amazonaws.com/' . $plugin_slug . '.zip';
} elseif ( is_array( $plugin_data ) ) {
$plug[ 'version' ] = $plugin_data[ 'version' ];
$plug[ 'source' ] = $plugin_data[ 'url' ];
}
$plug[ 'required' ] = false;
$plug[ 'message' ] = false;
$plug[ 'slug' ] = $plugin_slug;
$plugin_arr[] = $plug;
}
$config = array(
'id' => 'tgmpa',
'default_path' => '',
'menu' => 'tgma-install-plugins',
'parent_slug' => 'fox',
'capability' => 'edit_theme_options',
'has_notices' => true,
'dismissable' => true,
'dismiss_msg' => '',
'is_automatic' => true,
'message' => '',
);
tgmpa( $plugin_arr, $config );
}
/**
* Enqueue Media
* ------------------------------------------------------------ */
function wp_enqueue_media() {
wp_enqueue_media();
}
/**
* Enqueue javascript & style for admin
* @since Fox 2.2
* ------------------------------------------------------------ */
function enqueue() {
// We need to upload image/media constantly
wp_enqueue_media();
// admin css
$currentScreen = get_current_screen();
if ( 'jetpack_page_stats' != $currentScreen->id ) {
wp_enqueue_style( 'wi-admin', FOX_ADMIN_URL . 'css/admin.css', array( 'wp-color-picker', 'wp-mediaelement' ), FOX_VERSION );
}
// admin javascript
wp_enqueue_script( 'wi-admin', FOX_ADMIN_URL . 'js/admin.js', array( 'wp-color-picker', 'wp-mediaelement' ), FOX_VERSION, true );
// localize javascript
$jsdata = apply_filters( 'wiadminjs', array() );
wp_localize_script( 'wi-admin', 'WITHEMES_ADMIN' , $jsdata );
}
/**
* Localization some text
* @since Fox 2.2
* ------------------------------------------------------------ */
function l10n( $jsdata ) {
$jsdata[ 'l10n' ] = array(
'choose_image' => esc_html__( 'Choose Image', 'wi' ),
'change_image' => esc_html__( 'Change Image', 'wi' ),
'upload_image' => esc_html__( 'Upload Image', 'wi' ),
'choose_images' => esc_html__( 'Choose Images', 'wi' ),
'change_images' => esc_html__( 'Change Images', 'wi' ),
'upload_images' => esc_html__( 'Upload Images', 'wi' ),
'choose_file' => esc_html__( 'Choose File', 'wi' ),
'change_file' => esc_html__( 'Change File', 'wi' ),
'upload_file' => esc_html__( 'Upload File', 'wi' ),
);
return $jsdata;
}
/**
* Metaboxes
* @return $metaboxes
*
* @modified since 2.4
* @since Fox 2.2
* ------------------------------------------------------------ */
function metaboxes( $metaboxes ) {
include FOX_ADMIN_PATH . 'page-metaboxes.php';
include FOX_ADMIN_PATH . 'post-metaboxes.php';
return $metaboxes;
}
/**
* Term Metaboxes
* @since Fox 4.0
* ------------------------------------------------------------ */
function term_metaboxes( $metaboxes ) {
$sidebars = [
'' => 'Default',
'sidebar-left' => 'Sidebar Left',
'sidebar-right' => 'Sidebar Right',
'no-sidebar' => 'No Sidebar',
];
$layouts = array_merge( [ '' => 'Default' ], fox_archive_layout_support() );
$toparea_layouts = array_merge( [ '' => 'Default' ], fox_topbar_layout_support() );
$fields = [];
$fields[] = [
'id' => 'layout',
'name' => 'Layout',
'type' => 'select',
'options' => $layouts,
'std' => '',
];
$fields[] = [
'id' => 'sidebar_state',
'name' => 'Sidebar State',
'type' => 'select',
'options' => $sidebars,
'std' => '',
];
$fields[] = [
'id' => 'toparea_display',
'name' => 'Toparea displays',
'type' => 'select',
'options' => [
'' => 'Default',
'none' => 'None',
'view' => 'Most Viewed Posts',
'comment_count' => 'Most Commented Posts',
'featured' => 'Featured Posts (Starred Posts)',
],
'std' => '',
];
$fields[] = [
'id' => 'toparea_layout',
'name' => 'Toparea Layout',
'type' => 'select',
'options' => $toparea_layouts,
'std' => '',
];
$fields[] = [
'id' => 'toparea_number',
'name' => 'Toparea number of posts to show',
'type' => 'text',
'std' => '',
];
$fields[] = [
'id' => 'thumbnail',
'name' => 'Thumbnail',
'desc' => 'Used in grid of categories.',
'type' => 'image',
];
$fields[] = [
'id' => 'background_image',
'name' => 'Background Image',
'desc' => 'Used in category page as the header background.',
'type' => 'image',
];
$fields[] = [
'id' => 'priority',
'name' => 'Priority',
'desc' => 'If post has simultaneously cateogry A - priority 5 and category B - priority 10 then B will be chosen as primary category',
'type' => 'text',
];
$metaboxes[ 'term-settings' ] = array (
'id' => 'term-settings',
'screen' => array( 'category', 'post_tag' ),
'fields' => $fields,
);
return $metaboxes;
}
}
Fox_Admin::instance()->init();
endif; // class exists