*/ class Advanced_Related_Posts_Admin { /** * The ID of this plugin. * * @since 1.0.0 * @access private * @var string $plugin_name The ID of this plugin. */ private $plugin_name; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** * The capability of this plugin. * * @since 1.0.0 * @access private * @var string $capability The capability for users access to this plugin. */ private $capability; /** * The settings object of this plugin. * * @since 1.0.0 * @access private * @var object $settings_obj The settings object of this plugin. */ private $settings_obj; /** * The settings object of this plugin. * * @since 1.0.0 * @access private * @var object $general_settings_obj The general settings object of this plugin. */ private $general_settings_obj; /** * Initialize the class and set its properties. * * @since 1.0.0 * @param string $plugin_name The name of this plugin. * @param string $version The version of this plugin. */ public function __construct( $plugin_name, $version ) { $this->plugin_name = $plugin_name; $this->version = $version; } /** * Register the stylesheets for the admin area. * * @since 1.0.0 */ public function enqueue_styles( $hook_suffix ) { wp_enqueue_style($this->plugin_name . '-admin', plugin_dir_url(__FILE__) . 'css/admin.css', array(), $this->version, 'all'); wp_enqueue_style($this->plugin_name . '-sweetalert-css', ADVANCED_RELATED_POSTS_PUBLIC_URL . '/css/advanced-related-posts-sweetalert2.min.css', array(), $this->version, 'all'); if (false === strpos($hook_suffix, $this->plugin_name)) return; /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Advanced_Related_Posts_Loader as all of the hooks are defined * in that particular class. * * The Advanced_Related_Posts_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ wp_enqueue_style('wp-color-picker'); wp_enqueue_style( $this->plugin_name . '-banner', plugin_dir_url(__FILE__) . 'css/banner.css', array(), $this->version, 'all'); wp_enqueue_style( $this->plugin_name . '-bootstrap', plugin_dir_url(__FILE__) . 'css/bootstrap.min.css', array(), $this->version, 'all'); wp_enqueue_style( $this->plugin_name . '-font-awesome', plugin_dir_url(__FILE__) . 'css/advanced-related-posts-font-awesome.css', array(), $this->version, 'all'); wp_enqueue_style( $this->plugin_name . '-font-awesome-icons', plugin_dir_url(__FILE__) . 'css/advanced-related-posts-font-awesome-icons.css', array(), $this->version, 'all'); wp_enqueue_style( $this->plugin_name . '-select2', ADVANCED_RELATED_POSTS_PUBLIC_URL . '/css/advanced-related-posts-select2.min.css', array(), $this->version, 'all'); wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/advanced-related-posts-admin.css', array(), $this->version, 'all' ); wp_enqueue_style( $this->plugin_name .'-banner-css', ADVANCED_RELATED_POSTS_ADMIN_URL . '/css/advanced-related-posts-banner.css', array(), $this->version, 'all' ); } /** * Register the JavaScript for the admin area. * * @since 1.0.0 */ public function enqueue_scripts( $hook_suffix ) { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in Advanced_Related_Posts_Loader as all of the hooks are defined * in that particular class. * * The Advanced_Related_Posts_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ if (false !== strpos($hook_suffix, "plugins.php")){ wp_enqueue_script( $this->plugin_name . '-sweetalert-js', ADVANCED_RELATED_POSTS_PUBLIC_URL . '/js/advanced-related-posts-sweetalert2.all.min.js', array('jquery'), $this->version, true ); wp_enqueue_script( $this->plugin_name . '-admin', plugin_dir_url(__FILE__) . 'js/admin.js', array( 'jquery' ), $this->version, true ); wp_localize_script( $this->plugin_name . '-admin', 'AdvencedRelatedPostsAdmin', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), ) ); } if (false === strpos($hook_suffix, $this->plugin_name)) return; wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'jquery-effects-core' ); wp_enqueue_script( 'jquery-ui-sortable' ); wp_enqueue_script( 'jquery-ui-datepicker' ); wp_enqueue_editor(); wp_enqueue_media(); wp_enqueue_script( $this->plugin_name . '-color-picker-alpha', plugin_dir_url(__FILE__) . 'js/wp-color-picker-alpha.min.js', array( 'wp-color-picker' ), $this->version, true ); $color_picker_strings = array( 'clear' => __( 'Clear', $this->plugin_name ), 'clearAriaLabel' => __( 'Clear color', $this->plugin_name ), 'defaultString' => __( 'Default', $this->plugin_name ), 'defaultAriaLabel' => __( 'Select default color', $this->plugin_name ), 'pick' => __( 'Select Color', $this->plugin_name ), 'defaultLabel' => __( 'Color value', $this->plugin_name ), ); wp_localize_script( $this->plugin_name . '-color-picker-alpha', 'wpColorPickerL10n', $color_picker_strings ); /* ========================================== * Bootstrap * select2 * jQuery DataTables ========================================== */ wp_enqueue_script( $this->plugin_name . "-popper", plugin_dir_url(__FILE__) . 'js/popper.min.js', array( 'jquery' ), $this->version, true ); wp_enqueue_script( $this->plugin_name . "-bootstrap", plugin_dir_url(__FILE__) . 'js/bootstrap.min.js', array( 'jquery' ), $this->version, true ); wp_enqueue_script( $this->plugin_name . '-select2js', ADVANCED_RELATED_POSTS_PUBLIC_URL . '/js/advanced-related-posts-select2.min.js', array('jquery'), $this->version, true); wp_enqueue_script( $this->plugin_name . '-sweetalert-js', ADVANCED_RELATED_POSTS_PUBLIC_URL . '/js/advanced-related-posts-sweetalert2.all.min.js', array('jquery'), $this->version, true ); /* ================================================ Advanced related admin dashboard scripts (and for AJAX) ================================================ */ wp_enqueue_script( $this->plugin_name . "-functions", plugin_dir_url(__FILE__) . 'js/functions.js', array( 'jquery', 'wp-color-picker' ), $this->version, true ); wp_enqueue_script( $this->plugin_name . "-admin-styles", plugin_dir_url(__FILE__) . 'js/partials/advanced-related-posts-admin-styles.js', array('jquery', 'wp-color-picker'), $this->version, true); wp_enqueue_script( $this->plugin_name . '-ajax', plugin_dir_url(__FILE__) . 'js/advanced-related-posts-admin-ajax.js', array('jquery', 'wp-color-picker'), $this->version, true); wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/advanced-related-posts-admin.js', array( 'jquery', 'wp-color-picker' ), $this->version, true ); $arp_banner_date = $this->ays_arp_update_banner_time();; wp_localize_script( $this->plugin_name, 'AdvencedRelatedPostsAdmin', array( 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'defaultThumbnailUrl' => ADVANCED_RELATED_POSTS_ADMIN_URL . '/images/icons/icon-arp-default.png', 'addImage' => __( 'Add Image' , $this->plugin_name ), 'editImage' => __( 'Edit Image' , $this->plugin_name ), 'upload' => __( 'Upload' , $this->plugin_name ), 'excludeCategories' => __( 'Exclude Categories' , $this->plugin_name ), 'arpBannerDate' => $arp_banner_date, ) ); wp_localize_script( $this->plugin_name . '-ajax', 'arp_ajax', array( 'ajax_url' => admin_url('admin-ajax.php'), "emptyEmailError" => __( 'Email field is empty', $this->plugin_name), "invalidEmailError" => __( 'Invalid Email address', $this->plugin_name), 'selectUser' => __( 'Select user', $this->plugin_name), 'pleaseEnterMore' => __( "Please enter 1 or more characters", $this->plugin_name ), 'searching' => __( "Searching...", $this->plugin_name ), 'activated' => __( "Activated", $this->plugin_name ), 'errorMsg' => __( "Error", $this->plugin_name ), 'loadResource' => __( "Can't load resource.", $this->plugin_name ), 'somethingWentWrong' => __( "Maybe something went wrong.", $this->plugin_name ), 'greateJob' => __( 'Great job', $this->plugin_name), 'formMoreDetailed' => __( 'For more detailed configuration visit', $this->plugin_name), 'greate' => __( 'Great!', $this->plugin_name), )); wp_enqueue_script('jquery'); wp_enqueue_script( $this->plugin_name .'-banner-js', ADVANCED_RELATED_POSTS_ADMIN_URL . '/js/advanced-related-posts-banner.js', array( 'jquery' ), $this->version, true ); } public function ays_AdvencedRelatedPosts_VersionCompare($version1, $operator, $version2) { $_fv = intval ( trim ( str_replace ( '.', '', $version1 ) ) ); $_sv = intval ( trim ( str_replace ( '.', '', $version2 ) ) ); if (strlen ( $_fv ) > strlen ( $_sv )) { $_sv = str_pad ( $_sv, strlen ( $_fv ), 0 ); } if (strlen ( $_fv ) < strlen ( $_sv )) { $_fv = str_pad ( $_fv, strlen ( $_sv ), 0 ); } return version_compare ( ( string ) $_fv, ( string ) $_sv, $operator ); } /** * Register the administration menu for this plugin into the WordPress Dashboard menu. * * @since 1.0.0 */ public function add_plugin_admin_menu(){ /* * Add a settings page for this plugin to the Settings menu. * * NOTE: Alternative menu locations are available via WordPress administration menu functions. * * Administration Menus: http://codex.wordpress.org/Administration_Menus * */ $this->capability = $this->ays_related_posts_capabilities(); $capability = $this->capability; $hook_related_posts = add_menu_page( 'Related Posts', 'Related Posts', $this->capability, $this->plugin_name, array($this, 'display_plugin_under_posts_page'), ADVANCED_RELATED_POSTS_ADMIN_URL . '/images/icons/advanced-relative-posts.svg', '6.27' ); add_action( "load-$hook_related_posts", array( $this, 'add_tabs' )); } public function add_plugin_widget_settings_submenu(){ $hook_settings = add_submenu_page( $this->plugin_name, __('Widget settings', $this->plugin_name), __('Widget settings', $this->plugin_name), $this->capability, $this->plugin_name . '-wiget-settings', array($this, 'display_plugin_wiget_settings_page') ); $this->settings_obj = new Advanced_Related_Posts_Settings_Actions($this->plugin_name); add_action( "load-$hook_settings", array( $this, 'add_tabs' )); } public function add_plugin_under_posts_submenu(){ $hook_under_posts = add_submenu_page( $this->plugin_name, __('Display after post', $this->plugin_name), __('Display after post', $this->plugin_name), $this->capability, $this->plugin_name, array($this, 'display_plugin_under_posts_page') ); $this->settings_obj = new Advanced_Related_Posts_Settings_Actions($this->plugin_name); add_action( "load-$hook_under_posts", array( $this, 'add_tabs' )); } public function add_plugin_general_settings_submenu(){ $hook_general_settings = add_submenu_page( $this->plugin_name, __('General Settings', $this->plugin_name), __('General Settings', $this->plugin_name), $this->capability, $this->plugin_name . '-general-settings', array($this, 'display_plugin_arp_general_settings_page') ); $this->general_settings_obj = new Arp_General_Settings_Actions($this->plugin_name); add_action( "load-$hook_general_settings", array( $this, 'add_tabs' )); } public function add_plugin_featured_plugins_submenu(){ $hook_our_products = add_submenu_page( $this->plugin_name, __('Our products', $this->plugin_name), __('Our products', $this->plugin_name), 'manage_options', $this->plugin_name . '-featured-plugins', array($this, 'display_plugin_featured_plugins_page') ); add_action( "load-$hook_our_products", array( $this, 'add_tabs' )); } public function add_plugin_related_posts_features_submenu(){ $hook_pro_features = add_submenu_page( $this->plugin_name, __('PRO Features', $this->plugin_name), __('PRO Features', $this->plugin_name), 'manage_options', $this->plugin_name . '-related-posts-features', array($this, 'display_plugin_related_posts_features_page') ); add_action( "load-$hook_pro_features", array( $this, 'add_tabs' )); } public function display_plugin_wiget_settings_page(){ include_once('partials/settings/actions/advanced-related-posts-settings-actions.php'); } public function display_plugin_under_posts_page(){ include_once('partials/under-posts/actions/advanced-related-posts-under-posts-actions.php'); } public function display_plugin_arp_general_settings_page(){ include_once('partials/general-settings/advanced-related-posts-general-settings.php'); } public function display_plugin_featured_plugins_page(){ include_once('partials/features/advanced-related-posts-plugin-featured-display.php'); } public function display_plugin_related_posts_features_page(){ include_once('partials/features/advanced-related-posts-features-display.php'); } // Widget public function load_advanced_related_post_widget(){ require_once ADVANCED_RELATED_POSTS_DIR . "/widget/advanced-related-posts-widget.php"; register_widget( 'Advanced_Related_Posts_Widget' ); } /** * Add settings action link to the plugins page. * * @since 1.0.0 */ public function add_action_links($links){ /* * Documentation : https://codex.wordpress.org/Plugin_API/Filter_Reference/plugin_action_links_(plugin_file_name) */ $settings_link = array( '' . __('Settings', $this->plugin_name) . '', // '' . __('Demo', $this->plugin_name) . '', '' . __('Upgrade 30% Sale', $this->plugin_name) . '', ); return array_merge($settings_link, $links); } public function add_tabs() { $screen = get_current_screen(); if ( ! $screen) { return; } $screen->add_help_tab( array( 'id' => 'arp_help_tab', 'title' => __( 'General Information: '), 'content' => '
' . __( 'Related Posts plugin allows you to show a related posts list on your website after a post or via a widget. The plugin offers a range of features, including custom thumbnails, meta box settings, advanced styles, and more. The plugin is an essential tool to introduce your page visitors to other related content, boost site engagement, and increase pageviews. Furthermore, it allows you to fully customize your contextual related posts list without any need for tech skills.', $this->plugin_name ).'
' ) ); $screen->set_help_sidebar( '' . __( 'For more information:', $this->plugin_name) . '
' . '' . __( 'Youtube video tutorials' , $this->plugin_name ) . '
' . '' . __( 'Documentation', $this->plugin_name ) . '
' . '' . __( 'Related Posts plugin Premium version', $this->plugin_name ) . '
' ); } public function add_plugin_row_meta($meta, $file) { if ($file == ADVANCED_RELATED_POSTS_BASENAME) { $meta[] = '' . esc_html__( 'Free Support', $this->plugin_name ) . ''; } return $meta; } protected function ays_related_posts_capabilities(){ global $wpdb; return 'manage_options'; // $sql = "SELECT meta_value FROM {$wpdb->prefix}aysquiz_settings WHERE `meta_key` = 'user_roles'"; // $result = $wpdb->get_var($sql); // $capability = 'manage_options'; // if($result !== null){ // $ays_user_roles = json_decode($result, true); // if(is_user_logged_in()){ // $current_user = wp_get_current_user(); // $current_user_roles = $current_user->roles; // $ishmar = 0; // foreach($current_user_roles as $r){ // if(in_array($r, $ays_user_roles)){ // $ishmar++; // } // } // if($ishmar > 0){ // $capability = "read"; // } // } // } // return $capability; } public function ays_advanced_related_posts_admin_ajax(){ global $wpdb; $results = array( "status" => false ); $function = isset($_REQUEST['function']) ? sanitize_text_field( $_REQUEST['function'] ) : null; if($function !== null){ $results = array(); switch ($function) { case 'deactivate_plugin_option_arp': // Deactivate plugin AJAX action $results = $this->deactivate_plugin_option_arp(); break; case 'ays_advanced_related_posts_exlude_categories': // Exclude Categories $results = $this->ays_advanced_related_posts_exlude_categories(); break; } ob_end_clean(); $ob_get_clean = ob_get_clean(); echo json_encode( $results ); wp_die(); } ob_end_clean(); $ob_get_clean = ob_get_clean(); echo json_encode( $results ); wp_die(); } public function deactivate_plugin_option_arp(){ $request_value = sanitize_text_field( $_REQUEST['upgrade_plugin'] ); $upgrade_option = get_option( 'ays_advanced_related_posts_upgrade_plugin', '' ); if($upgrade_option === ''){ add_option( 'ays_advanced_related_posts_upgrade_plugin', $request_value ); }else{ update_option( 'ays_advanced_related_posts_upgrade_plugin', $request_value ); } ob_end_clean(); $ob_get_clean = ob_get_clean(); echo json_encode( array( 'option' => get_option( 'ays_advanced_related_posts_upgrade_plugin', '' ) ) ); wp_die(); } public function ays_advanced_related_posts_exlude_categories(){ $search = isset($_REQUEST['search']) && sanitize_text_field( $_REQUEST['search'] ) != '' ? sanitize_text_field( $_REQUEST['search'] ) : null; $checked = isset($_REQUEST['val']) && sanitize_text_field( $_REQUEST['val'] ) !='' ? sanitize_text_field( $_REQUEST['val'] ) : null; if($search != null){ $get_terms = get_terms( array( 'taxonomy' => array( 'category' ), 'name__like' => $search, ) ); } $response = array( 'results' => array() ); $category_name = ''; $category_id = ''; foreach ($get_terms as $key => $get_term) { $category_name = isset($get_term->name) && $get_term->name != '' ? $get_term->name : ''; $category_id = isset($get_term->term_id) && $get_term->term_id != '' ? $get_term->term_id : ''; if ($checked !== null) { if (in_array($category_id, $checked)) { continue; }else{ $response['results'][] = array( 'id' => $category_id, 'text' => $category_name ); } }else{ $response['results'][] = array( 'id' => $category_id, 'text' => $category_name, ); } } ob_end_clean(); $ob_get_clean = ob_get_clean(); echo json_encode($response); wp_die(); } //Sale Banner Start public function ays_arp_sale_baner(){ if (!isset($_GET['page']) || strpos($_GET['page'], $this->plugin_name) === false ) return; if(isset($_POST['ays_arp_sale_btn'])){ update_option('ays_arp_sale_notification', 1); update_option('ays_arp_sale_date', current_time( 'mysql' )); } $ays_arp_sale_date = get_option('ays_arp_sale_date'); $current_date = current_time( 'mysql' ); $date_diff = strtotime($current_date) - intval(strtotime($ays_arp_sale_date)) ; $val = 60*60*24*3; $days_diff = $date_diff / $val; if(intval($days_diff) > 0 ){ update_option('ays_arp_sale_notification', 0); } $ays_arp_ishmar = intval(get_option('ays_arp_sale_notification')); if($ays_arp_ishmar == 0 ){ // $this->ays_arp_sale_message($ays_arp_ishmar); // $this->ays_arp_black_friday_message($ays_arp_ishmar); // $this->ays_arp_new_mega_bundle_message_2024( $ays_arp_ishmar ); $this->ays_arp_new_sale_message($ays_arp_ishmar); } } /* ========================================== Sale Banner | Start ========================================== */ // New Mega Bundle 2024 public function ays_arp_new_mega_bundle_message_2024( $ishmar ){ if($ishmar == 0 ){ $content = array(); $content[] = '
';
$content[] = '
';
// $content[] = 'plugin_name); ?> WordPress.org
0 ){ update_option('ays_arp_banner_time', $next_3_days); } return $get_ays_arp_banner_time; } /** * Determine if the plugin/addon installations are allowed. * * @since 1.3.9 * * @param string $type Should be `plugin` or `addon`. * * @return bool */ public static function ays_arp_can_install( $type ) { return self::ays_arp_can_do( 'install', $type ); } /** * Determine if the plugin/addon activations are allowed. * * @since 1.3.9 * * @param string $type Should be `plugin` or `addon`. * * @return bool */ public static function ays_arp_can_activate( $type ) { return self::ays_arp_can_do( 'activate', $type ); } /** * Determine if the plugin/addon installations/activations are allowed. * * @since 1.3.9 * * @param string $what Should be 'activate' or 'install'. * @param string $type Should be `plugin` or `addon`. * * @return bool */ public static function ays_arp_can_do( $what, $type ) { if ( ! in_array( $what, array( 'install', 'activate' ), true ) ) { return false; } if ( ! in_array( $type, array( 'plugin', 'addon' ), true ) ) { return false; } $capability = $what . '_plugins'; if ( ! current_user_can( $capability ) ) { return false; } // Determine whether file modifications are allowed and it is activation permissions checking. if ( $what === 'install' && ! wp_is_file_mod_allowed( 'ays_arp_can_install' ) ) { return false; } // All plugin checks are done. if ( $type === 'plugin' ) { return true; } return false; } /** * Activate plugin. * * @since 1.0.0 * @since 1.3.9 Updated the permissions checking. */ public function ays_arp_activate_plugin() { // Run a security check. check_ajax_referer( $this->plugin_name . '-install-plugin-nonce', sanitize_key( $_REQUEST['_ajax_nonce'] ) ); // Check for permissions. if ( ! current_user_can( 'activate_plugins' ) ) { wp_send_json_error( esc_html__( 'Plugin activation is disabled for you on this site.', $this->plugin_name ) ); } $type = 'addon'; if ( isset( $_POST['plugin'] ) ) { if ( ! empty( $_POST['type'] ) ) { $type = sanitize_key( $_POST['type'] ); } $plugin = sanitize_text_field( wp_unslash( $_POST['plugin'] ) ); $activate = activate_plugins( $plugin ); if ( ! is_wp_error( $activate ) ) { if ( $type === 'plugin' ) { wp_send_json_success( esc_html__( 'Plugin activated.', $this->plugin_name ) ); } else { ( esc_html__( 'Addon activated.', $this->plugin_name ) ); } } } if ( $type === 'plugin' ) { wp_send_json_error( esc_html__( 'Could not activate the plugin. Please activate it on the Plugins page.', $this->plugin_name ) ); } wp_send_json_error( esc_html__( 'Could not activate the addon. Please activate it on the Plugins page.', $this->plugin_name ) ); } /** * Install addon. * * @since 1.0.0 * @since 1.3.9 Updated the permissions checking. */ public function ays_arp_install_plugin() { // Run a security check. check_ajax_referer( $this->plugin_name . '-install-plugin-nonce', sanitize_key( $_REQUEST['_ajax_nonce'] ) ); $generic_error = esc_html__( 'There was an error while performing your request.', $this->plugin_name ); $type = ! empty( $_POST['type'] ) ? sanitize_key( $_POST['type'] ) : ''; // Check if new installations are allowed. if ( ! self::ays_arp_can_install( $type ) ) { wp_send_json_error( $generic_error ); } $error = $type === 'plugin' ? esc_html__( 'Could not install the plugin. Please download and install it manually.', $this->plugin_name ) : ""; $plugin_url = ! empty( $_POST['plugin'] ) ? esc_url_raw( wp_unslash( $_POST['plugin'] ) ) : ''; if ( empty( $plugin_url ) ) { wp_send_json_error( $error ); } // Prepare variables. $url = esc_url_raw( add_query_arg( [ 'page' => 'advanced-related-posts-featured-plugins', ], admin_url( 'admin.php' ) ) ); ob_start(); $creds = request_filesystem_credentials( $url, '', false, false, null ); // Hide the filesystem credentials form. ob_end_clean(); // Check for file system permissions. if ( $creds === false ) { wp_send_json_error( $error ); } if ( ! WP_Filesystem( $creds ) ) { wp_send_json_error( $error ); } /* * We do not need any extra credentials if we have gotten this far, so let's install the plugin. */ require_once ADVANCED_RELATED_POSTS_DIR . 'includes/admin/class-advanced-related-posts-upgrader.php'; require_once ADVANCED_RELATED_POSTS_DIR . 'includes/admin/class-advanced-related-posts-install-skin.php'; require_once ADVANCED_RELATED_POSTS_DIR . 'includes/admin/class-advanced-related-posts-skin.php'; // Do not allow WordPress to search/download translations, as this will break JS output. remove_action( 'upgrader_process_complete', array( 'Language_Pack_Upgrader', 'async_upgrade' ), 20 ); // Create the plugin upgrader with our custom skin. $installer = new AdvancedRelatedPosts\Helpers\AdvancedRelatedPostsPluginSilentUpgrader( new Advanced_Related_Posts_Install_Skin() ); // Error check. if ( ! method_exists( $installer, 'install' ) ) { wp_send_json_error( $error ); } $installer->install( $plugin_url ); // Flush the cache and return the newly installed plugin basename. wp_cache_flush(); $plugin_basename = $installer->plugin_info(); if ( empty( $plugin_basename ) ) { wp_send_json_error( $error ); } $result = array( 'msg' => $generic_error, 'is_activated' => false, 'basename' => $plugin_basename, ); // Check for permissions. if ( ! current_user_can( 'activate_plugins' ) ) { $result['msg'] = $type === 'plugin' ? esc_html__( 'Plugin installed.', $this->plugin_name ) : ""; wp_send_json_success( $result ); } // Activate the plugin silently. $activated = activate_plugin( $plugin_basename ); remove_action( 'activated_plugin', array( 'ays_sccp_activation_redirect_method', 'gallery_p_gallery_activation_redirect_method', 'poll_maker_activation_redirect_method' ), 100 ); if ( ! is_wp_error( $activated ) ) { $result['is_activated'] = true; $result['msg'] = $type === 'plugin' ? esc_html__( 'Plugin installed and activated.', $this->plugin_name ) : esc_html__( 'Addon installed and activated.', $this->plugin_name ); wp_send_json_success( $result ); } // Fallback error just in case. wp_send_json_error( $result ); } /** * List of AM plugins that we propose to install. * * @since 1.3.9 * * @return array */ protected function arp_get_am_plugins() { if ( !isset( $_SESSION ) ) { session_start(); } $images_url = ADVANCED_RELATED_POSTS_ADMIN_URL . '/images/icons/'; $plugin_slug = array( 'quiz-maker', 'survey-maker', 'poll-maker', 'ays-popup-box', 'gallery-photo-gallery', 'secure-copy-content-protection', 'chart-builder', 'easy-form', ); $plugin_url_arr = array(); foreach ($plugin_slug as $key => $slug) { if ( isset( $_SESSION['ays_arp_our_product_links'] ) && !empty( $_SESSION['ays_arp_our_product_links'] ) && isset( $_SESSION['ays_arp_our_product_links'][$slug] ) && !empty( $_SESSION['ays_arp_our_product_links'][$slug] ) ) { $plugin_url = (isset( $_SESSION['ays_arp_our_product_links'][$slug] ) && $_SESSION['ays_arp_our_product_links'][$slug] != "") ? esc_url( $_SESSION['ays_arp_our_product_links'][$slug] ) : ""; } else { $latest_version = $this->ays_arp_get_latest_plugin_version($slug); $plugin_url = 'https://downloads.wordpress.org/plugin/'. $slug .'.zip'; if ( $latest_version != '' ) { $plugin_url = 'https://downloads.wordpress.org/plugin/'. $slug .'.'. $latest_version .'.zip'; $_SESSION['ays_arp_our_product_links'][$slug] = $plugin_url; } } $plugin_url_arr[$slug] = $plugin_url; } $plugins_array = array( 'quiz-maker/quiz-maker.php' => array( 'icon' => $images_url . 'icon-quiz-128x128.png', 'name' => __( 'Quiz Maker', $this->plugin_name ), 'desc' => __( 'With our Quiz Maker plugin itβs easy to make a quiz in a short time.', $this->plugin_name ), 'desc_hidden' => __( 'You to add images to your quiz, order unlimited questions. Also you can style your quiz to satisfy your visitors.', $this->plugin_name ), 'wporg' => 'https://wordpress.org/plugins/quiz-maker/', 'buy_now' => 'https://ays-pro.com/wordpress/quiz-maker/', 'url' => $plugin_url_arr['quiz-maker'], ), 'survey-maker/survey-maker.php' => array( 'icon' => $images_url . 'icon-survey-128x128.png', 'name' => __( 'Survey Maker', $this->plugin_name ), 'desc' => __( 'Make amazing online surveys and get real-time feedback quickly and easily.', $this->plugin_name ), 'desc_hidden' => __( 'Learn what your website visitors want, need, and expect with the help of Survey Maker. Build surveys without limiting your needs.', $this->plugin_name ), 'wporg' => 'https://wordpress.org/plugins/survey-maker/', 'buy_now' => 'https://ays-pro.com/wordpress/survey-maker', 'url' => $plugin_url_arr['survey-maker'], ), 'poll-maker/poll-maker-ays.php' => array( 'icon' => $images_url . 'icon-poll-128x128.png', 'name' => __( 'Poll Maker', $this->plugin_name ), 'desc' => __( 'Create amazing online polls for your WordPress website super easily.', $this->plugin_name ), 'desc_hidden' => __( 'Build up various types of polls in a minute and get instant feedback on any topic or product.', $this->plugin_name ), 'wporg' => 'https://wordpress.org/plugins/poll-maker/', 'buy_now' => 'https://ays-pro.com/wordpress/poll-maker/', 'url' => $plugin_url_arr['poll-maker'], ), 'ays-popup-box/ays-pb.php' => array( 'icon' => $images_url . 'icon-popup-128x128.png', 'name' => __( 'Popup Box', $this->plugin_name ), 'desc' => __( 'Popup everything you want! Create informative and promotional popups all in one plugin.', $this->plugin_name ), 'desc_hidden' => __( 'Attract your visitors and convert them into email subscribers and paying customers.', $this->plugin_name ), 'wporg' => 'https://wordpress.org/plugins/ays-popup-box/', 'buy_now' => 'https://ays-pro.com/wordpress/popup-box/', 'url' => $plugin_url_arr['ays-popup-box'], ), 'gallery-photo-gallery/gallery-photo-gallery.php' => array( 'icon' => $images_url . 'icon-gallery-128x128.png', 'name' => __( 'Gallery Photo Gallery', $this->plugin_name ), 'desc' => __( 'Create unlimited galleries and include unlimited images in those galleries.', $this->plugin_name ), 'desc_hidden' => __( 'Represent images in an attractive way. Attract people with your own single and multiple free galleries from your photo library.', $this->plugin_name ), 'wporg' => 'https://wordpress.org/plugins/gallery-photo-gallery/', 'buy_now' => 'https://ays-pro.com/wordpress/photo-gallery/', 'url' => $plugin_url_arr['gallery-photo-gallery'], ), 'secure-copy-content-protection/secure-copy-content-protection.php' => array( 'icon' => $images_url . 'icon-sccp-128x128.png', 'name' => __( 'Secure Copy Content Protection', $this->plugin_name ), 'desc' => __( 'Disable the right click, copy paste, content selection and copy shortcut keys on your website.', $this->plugin_name ), 'desc_hidden' => __( 'Protect web content from being plagiarized. Prevent plagiarism from your website with this easy to use plugin.', $this->plugin_name ), 'wporg' => 'https://wordpress.org/plugins/secure-copy-content-protection/', 'buy_now' => 'https://ays-pro.com/wordpress/secure-copy-content-protection/', 'url' => $plugin_url_arr['secure-copy-content-protection'], ), 'chart-builder/chart-builder.php' => array( 'icon' => $images_url . 'icon-chart-128x128.png', 'name' => __( 'Chart Builder', $this->plugin_name ), 'desc' => __( 'Chart Builder plugin allows you to create beautiful charts', $this->plugin_name ), 'desc_hidden' => __( ' and graphs easily and quickly.', $this->plugin_name ), 'wporg' => 'https://wordpress.org/plugins/chart-builder/', 'buy_now' => 'https://ays-pro.com/wordpress/chart-builder/', 'url' => $plugin_url_arr['chart-builder'], ), 'easy-form/easy-form.php' => array( 'icon' => $images_url . 'icon-easyform-128x128.png', 'name' => __( 'Easy Form', 'chart-builder' ), 'desc' => __( 'Choose the best WordPress form builder plugin. ', 'chart-builder' ), 'desc_hidden' => __( 'Create contact forms, payment forms, surveys, and many more custom forms. Build forms easily with us.', 'chart-builder' ), 'wporg' => 'https://wordpress.org/plugins/easy-form/', 'buy_now' => 'https://ays-pro.com/wordpress/easy-form', 'url' => $plugin_url_arr['easy-form'], ), ); return $plugins_array; } protected function ays_arp_get_latest_plugin_version( $slug ){ if ( is_null( $slug ) || empty($slug) ) { return ""; } $version_latest = ""; if ( ! function_exists( 'plugins_api' ) ) { require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); } // set the arguments to get latest info from repository via API ## $args = array( 'slug' => $slug, 'fields' => array( 'version' => true, ) ); /** Prepare our query */ $call_api = plugins_api( 'plugin_information', $args ); /** Check for Errors & Display the results */ if ( is_wp_error( $call_api ) ) { $api_error = $call_api->get_error_message(); } else { //echo $call_api; // everything ## if ( ! empty( $call_api->version ) ) { $version_latest = $call_api->version; } } return $version_latest; } /** * Get AM plugin data to display in the Addons section of About tab. * * @since 6.4.0.4 * * @param string $plugin Plugin slug. * @param array $details Plugin details. * @param array $all_plugins List of all plugins. * * @return array */ protected function arp_get_plugin_data( $plugin, $details, $all_plugins ) { $have_pro = ( ! empty( $details['pro'] ) && ! empty( $details['pro']['plug'] ) ); $show_pro = false; $plugin_data = array(); if ( $have_pro ) { if ( array_key_exists( $plugin, $all_plugins ) ) { if ( is_plugin_active( $plugin ) ) { $show_pro = true; } } if ( array_key_exists( $details['pro']['plug'], $all_plugins ) ) { $show_pro = true; } if ( $show_pro ) { $plugin = $details['pro']['plug']; $details = $details['pro']; } } if ( array_key_exists( $plugin, $all_plugins ) ) { if ( is_plugin_active( $plugin ) ) { // Status text/status. $plugin_data['status_class'] = 'status-active'; $plugin_data['status_text'] = esc_html__( 'Active', $this->plugin_name ); // Button text/status. $plugin_data['action_class'] = $plugin_data['status_class'] . ' ays-arp-card__btn-info disabled'; $plugin_data['action_text'] = esc_html__( 'Activated', $this->plugin_name ); $plugin_data['plugin_src'] = esc_attr( $plugin ); } else { // Status text/status. $plugin_data['status_class'] = 'status-installed'; $plugin_data['status_text'] = esc_html__( 'Inactive', $this->plugin_name ); // Button text/status. $plugin_data['action_class'] = $plugin_data['status_class'] . ' ays-arp-card__btn-info'; $plugin_data['action_text'] = esc_html__( 'Activate', $this->plugin_name ); $plugin_data['plugin_src'] = esc_attr( $plugin ); } } else { // Doesn't exist, install. // Status text/status. $plugin_data['status_class'] = 'status-missing'; if ( isset( $details['act'] ) && 'go-to-url' === $details['act'] ) { $plugin_data['status_class'] = 'status-go-to-url'; } $plugin_data['status_text'] = esc_html__( 'Not Installed', $this->plugin_name ); // Button text/status. $plugin_data['action_class'] = $plugin_data['status_class'] . ' ays-arp-card__btn-info'; $plugin_data['action_text'] = esc_html__( 'Install Plugin', $this->plugin_name ); $plugin_data['plugin_src'] = esc_url( $details['url'] ); } $plugin_data['details'] = $details; return $plugin_data; } /** * Display the Addons section of About tab. * * @since 1.3.9 */ public function arp_output_about_addons() { if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $all_plugins = get_plugins(); $am_plugins = $this->arp_get_am_plugins(); $can_install_plugins = self::ays_arp_can_install( 'plugin' ); $can_activate_plugins = self::ays_arp_can_activate( 'plugin' ); $content = ''; $content.= ''. wp_kses_post( $plugin_data['details']['desc'] ) .' '. wp_kses_post( $plugin_data['details']['desc_hidden'] ) .'