advanced_demo_import(); $this->get_started_notice(); //$this->review_notice(); } /** * Advance Demo import process * Active callback of advanced_import_demo_lists * return array */ public function advanced_demo_import(){ add_action( 'advanced_import_demo_lists', array( $this, 'demo_lists' ), 20 ); add_action( 'advanced_import_replace_post_ids', array( $this, 'replace_post_ids' ), 20 ); add_action( 'advanced_import_replace_term_ids', array( $this, 'replace_term_ids' ), 20 ); } /** * Advance Demo import process * Active callback of advanced_import_demo_lists * return array */ public function demo_lists( $demo_lists ) { $url = 'https://demo.acmethemes.com/wp-json/acmethemes-demo-api/v1/fetch_templates/?theme-slug=supermag'; $body_args = [ /*API version*/ 'api_version' => wp_get_theme()['Version'], /*lang*/ 'site_lang' => get_bloginfo( 'language' ), ]; $raw_json = wp_safe_remote_get( $url, [ 'timeout' => 100, 'body' => $body_args, ] ); if ( ! is_wp_error( $raw_json ) ) { $demo_server = json_decode( wp_remote_retrieve_body( $raw_json ), true ); if( is_array( $demo_server )){ return array_merge( $demo_lists, $demo_server ); } } return array_merge( $demo_lists); } /** * Advance Demo import process * Active callback of advanced_import_replace_post_ids * return array */ public function replace_post_ids( $replace_post_ids ){ /*Post IDS*/ $post_ids = array( 'supermag-feature-post-one', 'supermag-feature-post-two', ); return array_merge( $replace_post_ids,$post_ids ); } /** * Advance Demo import process * Active callback of advanced_import_replace_term_ids * return array */ public function replace_term_ids( $replace_term_ids ){ /*Terms IDS*/ $term_ids = array( 'supermag-feature-cat', 'supermag-feature-side-from-category', ); return array_merge( $replace_term_ids, $term_ids ); } /** * Get Started Notice * * Handle Getting Started Functions * return void */ private function get_started_notice(){ add_action( 'wp_loaded', array( $this, 'admin_notice' ), 20 ); add_action( 'wp_loaded', array( $this, 'hide_notices' ), 15 ); add_action( 'wp_ajax_at_getting_started', array( $this, 'install_advanced_import' ) ); } /** * Get Started Notice * Active callback of wp_loaded * return void */ public function admin_notice() { /*Check for notice nag*/ $notice_nag = get_option( 'supermag_admin_notice_welcome' ); if ( ! $notice_nag ) { wp_enqueue_style( 'supermag-notice', get_template_directory_uri() . '/acmethemes/admin-notice/admin-notice.css', array(), '3.0.0' ); wp_enqueue_script( 'supermag-adi-install', get_template_directory_uri() . '/acmethemes/admin-notice/admin-notice.js', array( 'jquery' ), '', true ); $translation = array( 'btn_text' => esc_html__( 'Processing...', 'supermag' ), 'nonce' => wp_create_nonce( 'supermag_demo_import_nonce' ) ); wp_localize_script( 'supermag-adi-install', 'supermag_adi_install', $translation ); /*admin notice hook*/ add_action( 'admin_notices', array( $this, 'getting_started' ) ); } } /** * Get Started Notice * Active callback of wp_loaded * return void */ public static function hide_notices() { if ( isset( $_GET['at-gsm-hide-notice'] ) && isset( $_GET['at_gsm_admin_notice_nonce'] ) ) { // WPCS: input var ok. if ( ! wp_verify_nonce( wp_unslash( $_GET['at_gsm_admin_notice_nonce'] ), 'at_gsm_hide_notices_nonce' ) ) { // phpcs:ignore WordPress.VIP.ValidatedSanitizedInput.InputNotSanitized wp_die( __( 'Action failed. Please refresh the page and retry.', 'supermag' ) ); // WPCS: xss ok. } if ( ! current_user_can( 'manage_options' ) ) { wp_die( __( 'Cheatin’ huh?', 'supermag' ) ); // WPCS: xss ok. } $notice_type = sanitize_text_field( wp_unslash( $_GET['at-gsm-hide-notice'] ) ); update_option( 'supermag_admin_notice_' . $notice_type, 1 ); /*Update to Hide.*/ if ( 'welcome' === $_GET['at-gsm-hide-notice'] ) { update_option( 'supermag_admin_notice_' . $notice_type, 1 ); } else { // Show. delete_option( 'supermag_admin_notice_' . $notice_type ); } } } /** * Get Started Notice * Active callback of admin_notices * return void */ public function getting_started() { ?>
<?php esc_html_e( 'SuperMag', 'supermag' ); ?>

'. wp_get_theme()->get('Name'). '','','' ); ?>

'plugin', 'slug' => sanitize_key( wp_unslash( $slug ) ), ); $status['redirect'] = admin_url( '/themes.php?page=advanced-import&browse=all&at-gsm-hide-notice=welcome' ); if ( is_plugin_active_for_network( $plugin ) || is_plugin_active( $plugin ) ) { // Plugin is activated wp_send_json_success($status); } if ( ! current_user_can( 'install_plugins' ) ) { $status['errorMessage'] = __( 'Sorry, you are not allowed to install plugins on this site.', 'supermag' ); wp_send_json_error( $status ); } include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; include_once ABSPATH . 'wp-admin/includes/plugin-install.php'; // Looks like a plugin is installed, but not active. if ( file_exists( WP_PLUGIN_DIR . '/' . $slug ) ) { $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); $status['plugin'] = $plugin; $status['pluginName'] = $plugin_data['Name']; if ( current_user_can( 'activate_plugin', $plugin ) && is_plugin_inactive( $plugin ) ) { $result = activate_plugin( $plugin ); if ( is_wp_error( $result ) ) { $status['errorCode'] = $result->get_error_code(); $status['errorMessage'] = $result->get_error_message(); wp_send_json_error( $status ); } wp_send_json_success( $status ); } } $api = plugins_api( 'plugin_information', array( 'slug' => sanitize_key( wp_unslash( $slug ) ), 'fields' => array( 'sections' => false, ), ) ); if ( is_wp_error( $api ) ) { $status['errorMessage'] = $api->get_error_message(); wp_send_json_error( $status ); } $status['pluginName'] = $api->name; $skin = new WP_Ajax_Upgrader_Skin(); $upgrader = new Plugin_Upgrader( $skin ); $result = $upgrader->install( $api->download_link ); if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { $status['debug'] = $skin->get_upgrade_messages(); } if ( is_wp_error( $result ) ) { $status['errorCode'] = $result->get_error_code(); $status['errorMessage'] = $result->get_error_message(); wp_send_json_error( $status ); } elseif ( is_wp_error( $skin->result ) ) { $status['errorCode'] = $skin->result->get_error_code(); $status['errorMessage'] = $skin->result->get_error_message(); wp_send_json_error( $status ); } elseif ( $skin->get_errors()->get_error_code() ) { $status['errorMessage'] = $skin->get_error_messages(); wp_send_json_error( $status ); } elseif ( is_null( $result ) ) { require_once( ABSPATH . 'wp-admin/includes/file.php' ); WP_Filesystem(); global $wp_filesystem; $status['errorCode'] = 'unable_to_connect_to_filesystem'; $status['errorMessage'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.', 'supermag' ); // Pass through the error from WP_Filesystem if one was raised. if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() ); } wp_send_json_error( $status ); } $install_status = install_plugin_install_status( $api ); if ( current_user_can( 'activate_plugin', $install_status['file'] ) && is_plugin_inactive( $install_status['file'] ) ) { $result = activate_plugin( $install_status['file'] ); if ( is_wp_error( $result ) ) { $status['errorCode'] = $result->get_error_code(); $status['errorMessage'] = $result->get_error_message(); wp_send_json_error( $status ); } } wp_send_json_success( $status ); } /** * Get Started Notice * * Handle Rating/Review Notice * return void */ private function review_notice(){ add_action( 'after_setup_theme', array( $this, 'setup_review_notice' ) ); add_action( 'switch_theme', array( $this, 'remove_review_notice' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'review_notice_enqueue' ) ); } /** * Set the Time * Aso call other necessary functions * * Active callback of after_setup_theme * return void */ public function setup_review_notice() { // Set the installed time in `supermag_theme_installed_time` option table. $option = get_option('supermag_theme_installed_time' ); if ( ! $option ) { update_option('supermag_theme_installed_time', time() ); } add_action( 'admin_notices', array( $this, 'display_review_notice' ), 0 ); add_action( 'admin_init', array( $this, 'remove_theme_review_notice' ), 0 ); add_action( 'admin_init', array( $this, 'remove_theme_review_notice_partially' ), 0 ); } /** * Display review notice * Aso call other necessary functions * * Active callback of after_setup_theme * return void */ public function display_review_notice() { global $current_user; $user_id = $current_user->ID; $ignored_notice = get_user_meta( $user_id, 'remove_theme_review_notice', true ); $ignored_notice_partially = get_user_meta( $user_id, 'nag_remove_theme_review_notice_partially', true ); /** * Return from notice display if: * * 1. The theme installed is less than 15 days ago. * 2. If the user has ignored the message partially for 15 days. * 3. Dismiss always if clicked on 'I Already Did' button. */ if ( ( get_option('supermag_theme_installed_time' ) > strtotime( '-15 day' ) ) || ( $ignored_notice_partially > strtotime( '-15 day' ) ) || ( $ignored_notice ) ) { return; } ?>

' . esc_html( $current_user->display_name ) . '' ); ?>

ID; /* If user clicks to ignore the notice, add info to user meta */ if ( isset( $_GET['nag_remove_theme_review_notice'] ) && '0' == $_GET['nag_remove_theme_review_notice'] ) { add_user_meta( $user_id, 'remove_theme_review_notice', 'true', true ); } } /** * Remove notice partially * * Active callback of after_setup_theme * return void */ public function remove_theme_review_notice_partially() { global $current_user; $user_id = $current_user->ID; /* If user clicks to ignore the notice, add that to their user meta */ if ( isset( $_GET['nag_remove_theme_review_notice_partially'] ) && '0' == $_GET['nag_remove_theme_review_notice_partially'] ) { update_user_meta( $user_id, 'nag_remove_theme_review_notice_partially', time() ); } } /** * Remove the data set after the theme has been switched to other theme. * * Active callback of after_setup_theme * return void */ public function remove_review_notice() { global $current_user; $user_id = $current_user->ID; $theme_installed_time = get_option('supermag_theme_installed_time' ); $ignored_notice = get_user_meta( $user_id, 'remove_theme_review_notice', true ); $ignored_notice_partially = get_user_meta( $user_id, 'nag_remove_theme_review_notice_partially', true ); // Delete options data. if ( $theme_installed_time ) { delete_option('supermag_theme_installed_time' ); } // Delete permanent notice remove data. if ( $ignored_notice ) { delete_user_meta( $user_id, 'remove_theme_review_notice' ); } // Delete partial notice remove data. if ( $ignored_notice_partially ) { delete_user_meta( $user_id, 'nag_remove_theme_review_notice_partially' ); } } /** * Enqueue the required CSS file for theme review notice on admin page. */ public function review_notice_enqueue() { wp_enqueue_style( 'supermag-review-notice', get_template_directory_uri() . '/acmethemes/admin-notice/admin-notice.css' ); } } /** * Begins execution of the hooks. * * @since 1.0.0 */ function supermag_notice_handler( ) { return SuperMag_Notice_Handler::instance(); } supermag_notice_handler()->run(); /*For this theme only*/ if( !function_exists( 'supermag_ai_update_image_size') ){ function supermag_ai_update_image_size(){ /*Thumbnail Size*/ update_option( 'thumbnail_size_w', 500 ); update_option( 'thumbnail_size_h', 280 ); update_option( 'thumbnail_crop', 1 ); /*Medium Image Size*/ update_option( 'medium_size_w', 690 ); update_option( 'medium_size_h', 400 ); /*Large Image Size*/ update_option( 'large_size_w', 1080 ); update_option( 'large_size_h', 530 ); } } add_action( 'advanced_import_before_content_screen', 'supermag_ai_update_image_size' );