includes(); add_action( 'admin_notices', array( $this, 'add_notice' ), 1 ); add_action( 'admin_notices', array( $this, 'admin_notices' ) ); add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue' ) ); // AJAX. add_action( 'wp_ajax_astra-required-plugins', array( $this, 'required_plugin' ) ); add_action( 'wp_ajax_astra-required-plugin-activate', array( $this, 'required_plugin_activate' ) ); add_action( 'wp_ajax_astra-sites-backup-settings', array( $this, 'backup_settings' ) ); add_action( 'wp_ajax_astra-sites-set-reset-data', array( $this, 'set_reset_data' ) ); add_action( 'wp_ajax_astra-sites-activate-theme', array( $this, 'activate_theme' ) ); add_action( 'wp_ajax_astra-sites-getting-started-notice', array( $this, 'getting_started_notice' ) ); } /** * Close getting started notice for current user * * @since 1.3.5 * @return void */ function getting_started_notice() { update_user_meta( get_current_user_id(), '_astra_sites_gettings_started', true ); wp_send_json_success(); } /** * Activate theme * * @since 1.3.2 * @return void */ function activate_theme() { switch_theme( 'astra' ); wp_send_json_success( array( 'success' => true, 'message' => __( 'Theme Activated', 'astra-sites' ), ) ); } /** * Set reset data */ function set_reset_data() { if ( ! current_user_can( 'manage_options' ) ) { return; } global $wpdb; $post_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_astra_sites_imported_post'" ); $form_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_astra_sites_imported_wp_forms'" ); $term_ids = $wpdb->get_col( "SELECT term_id FROM {$wpdb->termmeta} WHERE meta_key='_astra_sites_imported_term'" ); wp_send_json_success( array( 'reset_posts' => $post_ids, 'reset_wp_forms' => $form_ids, 'reset_terms' => $term_ids, ) ); } /** * Backup our existing settings. */ function backup_settings() { if ( ! current_user_can( 'manage_options' ) ) { return; } $file_name = 'astra-sites-backup-' . date( 'd-M-Y-h-i-s' ) . '.json'; $old_settings = get_option( 'astra-settings', array() ); $upload_dir = Astra_Sites_Importer_Log::get_instance()->log_dir(); $upload_path = trailingslashit( $upload_dir['path'] ); $log_file = $upload_path . $file_name; $file_system = Astra_Sites_Importer_Log::get_instance()->get_filesystem(); // If file system fails? Then take a backup in site option. if ( false === $file_system->put_contents( $log_file, json_encode( $old_settings ), FS_CHMOD_FILE ) ) { update_option( 'astra_sites_' . $file_name, $old_settings ); } wp_send_json_success(); } /** * Add Admin Notice. */ function add_notice() { $theme_status = 'astra-sites-theme-' . $this->get_theme_status(); Astra_Notices::add_notice( array( 'id' => 'astra-theme-activation-nag', 'type' => 'error', 'show_if' => ( ! defined( 'ASTRA_THEME_SETTINGS' ) ) ? true : false, /* translators: 1: theme.php file*/ 'message' => sprintf( __( '
Astra Theme needs to be active for you to use currently installed "%1$s" plugin. Install & Activate Now
', 'astra-sites' ), ASTRA_SITES_NAME, esc_url( admin_url( 'themes.php?theme=astra' ) ), $theme_status ), 'dismissible' => true, 'dismissible-time' => WEEK_IN_SECONDS, ) ); } /** * Get theme install, active or inactive status. * * @since 1.3.2 * * @return string Theme status */ function get_theme_status() { $theme = wp_get_theme(); // Theme installed and activate. if ( 'Astra' === $theme->name || 'Astra' === $theme->parent_theme ) { return 'installed-and-active'; } // Theme installed but not activate. foreach ( (array) wp_get_themes() as $theme_dir => $theme ) { if ( 'Astra' === $theme->name || 'Astra' === $theme->parent_theme ) { return 'installed-but-inactive'; } } return 'not-installed'; } /** * Loads textdomain for the plugin. * * @since 1.0.1 */ function load_textdomain() { load_plugin_textdomain( 'astra-sites' ); } /** * Admin Notices * * @since 1.0.5 * @return void */ function admin_notices() { if ( ! defined( 'ASTRA_THEME_SETTINGS' ) ) { return; } add_action( 'plugin_action_links_' . ASTRA_SITES_BASE, array( $this, 'action_links' ) ); } /** * Show action links on the plugin screen. * * @param mixed $links Plugin Action links. * @return array */ function action_links( $links ) { $action_links = array( 'settings' => '' . esc_html__( 'See Library', 'astra-sites' ) . '', ); return array_merge( $action_links, $links ); } /** * Setter for $api_url * * @since 1.0.0 */ public static function set_api_url() { self::$api_url = apply_filters( 'astra_sites_api_url', 'https://websitedemos.net/wp-json/wp/v2/' ); } /** * Enqueue admin scripts. * * @since 1.3.2 Added 'install-theme.js' to install and activate theme. * @since 1.0.5 Added 'getUpgradeText' and 'getUpgradeURL' localize variables. * * @since 1.0.0 * * @param string $hook Current hook name. * @return void */ public function admin_enqueue( $hook = '' ) { wp_enqueue_script( 'astra-sites-install-theme', ASTRA_SITES_URI . 'inc/assets/js/install-theme.js', array( 'jquery', 'updates' ), ASTRA_SITES_VER, true ); wp_enqueue_style( 'astra-sites-install-theme', ASTRA_SITES_URI . 'inc/assets/css/install-theme.css', null, ASTRA_SITES_VER, 'all' ); $data = apply_filters( 'astra_sites_install_theme_localize_vars', array( 'installed' => __( 'Installed! Activating..', 'astra-sites' ), 'activating' => __( 'Activating..', 'astra-sites' ), 'activated' => __( 'Activated! Reloading..', 'astra-sites' ), 'installing' => __( 'Installing..', 'astra-sites' ), 'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ), ) ); wp_localize_script( 'astra-sites-install-theme', 'AstraSitesInstallThemeVars', $data ); if ( 'appearance_page_astra-sites' !== $hook ) { return; } global $is_IE, $is_edge; if ( $is_IE || $is_edge ) { wp_enqueue_script( 'astra-sites-eventsource', ASTRA_SITES_URI . 'inc/assets/js/eventsource.min.js', array( 'jquery', 'wp-util', 'updates' ), ASTRA_SITES_VER, true ); } // Fetch. wp_register_script( 'astra-sites-fetch', ASTRA_SITES_URI . 'inc/assets/js/fetch.umd.js', array( 'jquery' ), ASTRA_SITES_VER, true ); // API. wp_register_script( 'astra-sites-api', ASTRA_SITES_URI . 'inc/assets/js/astra-sites-api.js', array( 'jquery', 'astra-sites-fetch' ), ASTRA_SITES_VER, true ); // Admin Page. wp_enqueue_style( 'astra-sites-admin', ASTRA_SITES_URI . 'inc/assets/css/admin.css', ASTRA_SITES_VER, true ); wp_enqueue_script( 'astra-sites-admin-page', ASTRA_SITES_URI . 'inc/assets/js/admin-page.js', array( 'jquery', 'wp-util', 'updates' ), ASTRA_SITES_VER, true ); wp_enqueue_script( 'astra-sites-render-grid', ASTRA_SITES_URI . 'inc/assets/js/render-grid.js', array( 'wp-util', 'astra-sites-api', 'imagesloaded', 'jquery' ), ASTRA_SITES_VER, true ); $data = apply_filters( 'astra_sites_localize_vars', array( 'ApiURL' => self::$api_url, 'filters' => array( 'page_builder' => array( 'title' => __( 'Page Builder', 'astra-sites' ), 'slug' => 'astra-site-page-builder', 'trigger' => 'astra-api-category-loaded', ), 'categories' => array( 'title' => __( 'Categories', 'astra-sites' ), 'slug' => 'astra-site-category', 'trigger' => 'astra-api-category-loaded', ), ), ) ); wp_localize_script( 'astra-sites-api', 'astraSitesApi', $data ); // Use this for premium demos. $request_params = apply_filters( 'astra_sites_api_params', array( 'purchase_key' => '', 'site_url' => '', 'par-page' => 30, ) ); $data = apply_filters( 'astra_sites_render_localize_vars', array( 'sites' => $request_params, 'page-builders' => array(), 'categories' => array(), 'settings' => array(), 'default_page_builder' => Astra_Sites_Page::get_instance()->get_setting( 'page_builder' ), ) ); wp_localize_script( 'astra-sites-render-grid', 'astraRenderGrid', $data ); $data = apply_filters( 'astra_sites_localize_vars', array( 'debug' => ( ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || isset( $_GET['debug'] ) ) ? true : false, 'isPro' => defined( 'ASTRA_PRO_SITES_NAME' ) ? true : false, 'isWhiteLabeled' => Astra_Sites_White_Label::get_instance()->is_white_labeled(), 'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ), 'siteURL' => site_url(), 'docUrl' => 'https://wpastra.com/', 'getProText' => __( 'Get Agency Bundle', 'astra-sites' ), 'getProURL' => esc_url( 'https://wpastra.com/agency/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=wp-dashboard' ), 'getUpgradeText' => __( 'Upgrade', 'astra-sites' ), 'getUpgradeURL' => esc_url( 'https://wpastra.com/agency/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=wp-dashboard' ), '_ajax_nonce' => wp_create_nonce( 'astra-sites' ), 'requiredPlugins' => array(), 'XMLReaderDisabled' => ! class_exists( 'XMLReader' ) ? true : false, 'strings' => array( /* translators: %s are HTML tags. */ 'warningXMLReader' => sprintf( __( '%1$sRequired XMLReader PHP extension is missing on your server!%2$sAstra Sites import requires XMLReader extension to be installed. Please contact your web hosting provider and ask them to install and activate the XMLReader PHP extension.', 'astra-sites' ), '', '
', '