demos = include get_template_directory() . '/inc/admin/assets/demos.php'; }); $this->is_premium = preg_match( '/-pro/', wp_get_theme()->get( 'TextDomain' ) ); $this->current_user_id = get_current_user_id(); add_action( 'admin_menu', [ $this, 'blog_postx_info_page' ], 10 ); add_action( 'admin_enqueue_scripts', [ $this, 'admin_scripts' ] ); add_action( 'wp_ajax_blog_postx_importer_plugin_action', array( $this, 'blog_postx_importer_plugin_action' ) ); new Admin_Notices(); } /** * Function to enqueue scripts in admin page */ public function admin_scripts( $hook ) { if( 'widgets.php' === $hook ) return; if( $hook == 'toplevel_page_blog-postx-info' ) { wp_enqueue_style( 'blog-postx-info', get_template_directory_uri() . '/inc/admin/assets/admin-page.css', [], BLOG_POSTX_VERSION, 'all' ); wp_enqueue_script( 'blog-postx-info', get_template_directory_uri() . '/inc/admin/assets/admin-page.js', [], BLOG_POSTX_VERSION, [ 'strategy' => 'defer', 'in_footer' => true ] ); } wp_enqueue_script( 'blog-postx-notice', get_template_directory_uri() . '/inc/admin/assets/admin-notice.js', [], BLOG_POSTX_VERSION, [ 'strategy' => 'defer', 'in_footer' => true ] ); wp_enqueue_style( 'blog-postx-info-notice', get_template_directory_uri() . '/inc/admin/assets/admin-notice.css', [], BLOG_POSTX_VERSION, 'all' ); wp_localize_script( 'blog-postx-info', 'blogPostXThemeInfoObject', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), '_wpnonce' => wp_create_nonce( 'blog-postx-theme-info-nonce' ) )); wp_localize_script( 'blog-postx-notice', 'blogPostXNoticeOject', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), '_wpnonce' => wp_create_nonce( 'blog-postx-notice-nonce' ), 'welcomeOption' => 'blog_postx_welcome_notice_dismiss' )); } /** * Function to Blog Postx Info admin menu page * * @since 1.0.0 */ public function blog_postx_info_page() { add_menu_page( esc_html__( 'Blog Postx Info', 'blog-postx' ), esc_html__( 'Blog Postx Info', 'blog-postx' ), 'manage_options', 'blog-postx-info', [ $this, 'blog_postx_info_callback' ], '', 59 ); } /** * Callback function when registering Blog Postx Info admin menu page * * @since 1.0.0 */ public function blog_postx_info_callback() { $starter_sites_class = 'starter-sites-section-wrap'; if( array_key_exists( 'blog_postx_importer_activated', $_POST ) ) : $nonce = $_POST['blog_postx_importer_activated']; if ( wp_verify_nonce( $nonce, 'blog_postx_form_action' ) ) $starter_sites_class .= ' active'; endif; ?>
starter_sites(); $this->importer_modal(); ?>
get( 'Name' ); $theme_version = wp_get_theme()->get( 'Version' ); ?>

get_filter_tabs(); ?>
demos ) && is_array( $this->demos ) ) : echo '
'; $type = ''; foreach( $this->demos as $demo_slug => $demo ) : if( ! $this->is_premium ) $type = ( ! empty( $demo['type'] ) ) ? $demo['type'] : ''; $category = ( ! empty( $demo['tags'] ) && is_array( $demo['tags'] ) ) ? array_keys( $demo['tags'] ) : []; ?>
<?php echo esc_attr( $demo['name'] ); ?>

get_demo_button( $demo_slug, $demo['preview_url'], $demo['type'] ); ?>
'; endif; ?>
check_plugin_status( $this->importer_plugin_file ); $elementClass = 'canvas-footer'; $elementClass .= ' importer--' . $status; ?>
check_plugin_status( $this->importer_plugin_file ); if( ! in_array( $status, [ 'not-installed', 'inactive' ] ) ) : ?>
is_premium || $type == 'free' ): ?>
esc_html__( 'All', 'blog-postx' ) ]; if( ! empty( $this->demos ) && is_array( $this->demos ) ) : // for type if( ! $this->is_premium ) : foreach( $this->demos as $demo ) : $list_items = array_merge( $list_items, [ $demo['type'] => $this->get_demo_label( $demo['type'] ) ] ); endforeach; endif; // for category foreach( $this->demos as $demo ) : $list_items = array_merge( $list_items, $demo['tags'] ); endforeach; endif; if( ! empty( $list_items ) && is_array( $list_items ) ) : echo ''; endif; } /** * Get demo type label * * @since 1.0.0 */ public function get_demo_label( $type ) { if( ! $type ) return; switch( $type ) : case 'free': return esc_html__( 'Free', 'blog-postx' ); break; case 'pro': return esc_html__( 'Pro', 'blog-postx' ); break; default: return esc_html__( 'Default', 'blog-postx' ); break; endswitch; } /** * Function to get plugins details using REST API * * @since 1.0.0 */ public function get_plugins_details() { $plugins_to_add_args = [ [ 'author' => 'elemntor', 'slug' => [ 'elementor' ], 'directory' => [ 'elementor' => 'elementor' ], 'file' => [ 'elementor' => 'elementor.php' ] ], [ 'author' => 'blazethemes', 'slug' => [ 'news-kit-elementor-addons' ], 'directory' => [ 'news-kit-elementor-addons' => 'news-kit-elementor-addons' ], 'file' => [ 'news-kit-elementor-addons' => 'news-kit-elementor-addons.php', ], 'dependency' => [ 'news-kit-elementor-addons' => 'elementor' ] ] ]; $plugin_information = []; if( ! empty( array_column( $plugins_to_add_args, 'author' ) ) && count( array_column( $plugins_to_add_args, 'author' ) ) > 0 ) : if( ! empty( $plugins_to_add_args ) && is_array( $plugins_to_add_args ) ) : foreach( $plugins_to_add_args as $plugin ) : $base_url = 'https://api.wordpress.org/plugins/info/1.2/?action=query_plugins&request[author]='. $plugin['author']; $response = wp_remote_get( $base_url ); if ( is_array( $response ) && ! is_wp_error( $response ) ) : $headers = $response['headers']; // array of http header lines $body = json_decode( $response['body'], true ); // use the content if( ! empty( $body['plugins'] ) && is_array( $body['plugins'] ) ) : foreach( $body['plugins'] as $body_key => $body_value ) : if( in_array( $body_value['slug'], $plugin['slug'] ) ) : $body_value['directory'] = $plugin['directory'][ $body_value['slug'] ]; $body_value['file'] = $plugin['file'][ $body_value['slug'] ]; if( array_key_exists( 'dependency', $plugin ) ) $body_value['dependency'] = $plugin['dependency'][ $body_value['slug'] ]; $plugin_information[ $body_value['slug'] ] = $body_value; endif; endforeach; endif; endif; endforeach; endif; endif; return $plugin_information; } /** * check plugin installation and activation * * @since 1.0.0 */ public function check_plugin_status( $plugin_file ) { /** * Gives path to plugins folder */ $status = 'not-installed'; $path_to_plugin = WP_PLUGIN_DIR . '/' . esc_attr( $plugin_file ); if( file_exists( $path_to_plugin ) ) $status = ( is_plugin_active( $plugin_file ) ) ? 'active' : 'inactive'; return $status; } /** * Render plugin status button * * @since 1.0.0 */ public function plugin_status_button( $status, $importer = false, $args = [] ) { if( ! $status ) return; $label = $property = $button_property = $file = ''; $class = 'nexus-status'; switch( $status ) : case 'not-installed' : $label = $importer ? esc_html__( 'Here', 'blog-postx' ) : esc_html__( 'Install and Activate', 'blog-postx' ); $class .= ' action-trigger not-installed'; break; case 'active' : $class .= ' active'; $property = ' disabled'; $label = esc_html__( 'Installed & Activated', 'blog-postx' ); if( $importer ) : $property = ''; $class .= ' importer'; $label = esc_html__( 'Import', 'blog-postx' ); endif; break; case 'inactive' : $label = $importer ? esc_html__( 'activate', 'blog-postx' ) : esc_html__( 'Activate', 'blog-postx' ); $class .= ' inactive'; if( ! $importer ) $class .= ' action-trigger'; break; endswitch; if( ! empty( $args ) && is_array( $args ) ) : $file = $args['directory'] . '/' . $args['file']; $button_property = "data-link=". esc_url( $args['link'] ) ." data-file=". esc_attr( $file ) .""; endif; echo ''; } /** * Activate or install plugins ajax call * * @since 1.0.0 */ public function blog_postx_importer_plugin_action() { $this->plugin_active_install_action( 'blog-postx-theme-info-nonce' ); } /** * Activate or install plugins * * @since 1.0.0 */ public function plugin_active_install_action( $nonce = '' ) { check_ajax_referer( $nonce, '_wpnonce' ); if( ! current_user_can( 'install_plugins' ) || ! current_user_can( 'activate_plugins' ) ) : echo wp_send_json_error( 'You dont have permission to perform this action', 403 ); die(); endif; $_plugin_action = isset( $_POST['plugin_action'] ) ? sanitize_text_field( $_POST['plugin_action'] ) : ''; $importer_or_not = isset( $_POST['importer_or_not'] ) ? $_POST['importer_or_not'] : ''; $link = isset( $_POST['link'] ) ? esc_url( $_POST['link'] ) : ''; $file_path = isset( $_POST['file'] ) ? sanitize_text_field( $_POST['file'] ) : ''; if( $_plugin_action === 'inactive' ) { if( $file_path ) { activate_plugin( $file_path, '', false, true ); } $this->ajax_response['status'] = true; $this->ajax_response['message'] = ( $importer_or_not == 'true' ) ? esc_html__( 'Plugin activated', 'blog-postx' ) : esc_html__( 'Demo importer plugin activated', 'blog-postx' ); $this->send_ajax_response(); } else if( $_plugin_action === 'not-installed' ) { $download_link = esc_url( $link ); // Include required libs for installation require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; require_once ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php'; require_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php'; $skin = new \WP_Ajax_Upgrader_Skin(); $upgrader = new \Plugin_Upgrader( $skin ); $upgrader->install( $download_link ); activate_plugin( $file_path, '', false, true ); $this->ajax_response['status'] = true; $this->ajax_response['message'] = ( $importer_or_not == 'true' ) ? esc_html__( 'Plugin activated', 'blog-postx' ) : esc_html__( 'Demo importer plugin activated', 'blog-postx' ); $this->send_ajax_response(); } $this->ajax_response['status'] = false; $this->ajax_response['message'] = esc_html__( 'Error while trying to install or active the plugin.', 'blog-postx' ); $this->send_ajax_response(); } /** * send ajax response to ajax call in js file * * @since 1.0.0 */ public function send_ajax_response() { $json = wp_json_encode( $this->ajax_response ); echo $json; die(); } /** * Importer model * * @since 1.0.0 */ public function importer_modal() { ?>
demos ) && ! is_null( $this->demos ) ) : foreach ( $this->demos as $demo_slug => $demo_pack ) : ?>
restriction_message = esc_html__( "You dont have permission to perform this action", 'blog-postx' ); }); $this->notices_permission = get_theme_mod( 'disable_admin_notices', false ); if( ! $this->notices_permission ) add_action( 'admin_notices', [ $this, 'admin_welcome_notice' ] ); add_action( 'wp_ajax_blog_postx_admin_notice_ajax_call', [ $this, 'admin_notice_ajax_call' ] ); add_action( 'wp_ajax_blog_postx_importer_plugin_action_for_notice', [ $this, 'blog_postx_importer_plugin_action_for_notice' ] ); } /** * Admin Welcome notice * * @since 1.0.0 */ public function admin_welcome_notice() { if( ! current_user_can( 'manage_options' ) ) wp_die( $this->restriction_message ); if( isset( $_GET['page'] ) && in_array( $_GET['page'], [ 'blog-postx-info', 'blaze-system-info' ] ) ) return; if( get_option( 'blog_postx_welcome_notice_dismiss' ) ) return; $this->notice_wrapper_open('blog-postx-welcome-notice notice-info'); ?>

get_notice_preview(); ?> notice_wrapper_close(); } /** * Notice wrapper open * * @since 1.0.0 */ public function notice_wrapper_open( $classes = '' ) { if( $classes != '' ) { echo '
'; } else { echo '
'; } echo '
'; } /** * Notice wrapper open * * @since 1.0.0 */ public function notice_wrapper_close() { echo '
'; echo '
'; } /** * Notice Preview * * @since 1.0.0 */ public function get_notice_preview() { ?>
Welcome
restriction_message ); // check if user role is admin, if not display restriction message $dismiss_option = isset( $_POST['dismiss_option'] ) ? sanitize_text_field( $_POST['dismiss_option'] ) : ''; $is_temporary = isset( $_POST['is_temporary'] ) ? $_POST['is_temporary'] : false; if( $is_temporary ) : $duration = isset( $_POST['duration'] ) ? absint( $_POST['duration'] ) : 7; $count = isset( $_POST['count'] ) ? absint( $_POST['count'] ) : 1; $count_id = isset( $_POST['count_id'] ) ? sanitize_text_field( $_POST['count_id'] ) : ''; update_user_meta( get_current_user_id(), $dismiss_option, time() + $duration * 24 * 60 * 60 ); update_user_meta( get_current_user_id(), $count_id, $count ); else: update_option( $dismiss_option, true ); endif; $this->ajax_response['status'] = true; $this->ajax_response['message'] = esc_html__( 'Welcome notice hidden', 'blog-postx' ); $this->send_ajax_response(); wp_die(); } /** * Activate or install plugins * * @since 1.0.0 */ public function blog_postx_importer_plugin_action_for_notice() { $this->plugin_active_install_action( 'blog-postx-notice-nonce' ); } } endif;