display( 'Name' ).' '.esc_html__( 'Settings', 'news-portal' ), $theme->display( 'Name' ).' '.' '.esc_html__( 'Settings', 'news-portal' ), 'activate_plugins', 'news-portal-settings', array( $this, 'get_started_screen' ) );
}
/**
* Enqueue styles.
*/
public function about_theme_styles( $hook ) {
global $news_portal_version;
wp_enqueue_style( 'mt-theme-review-notice', get_template_directory_uri() . '/inc/theme-settings/assets/css/theme-review-notice.css', array(), esc_attr( $news_portal_version ) );
if ( 'appearance_page_news-portal-settings' != $hook && 'themes.php' != $hook ) {
return;
}
wp_enqueue_style( 'mt-theme-settings-style', get_template_directory_uri() . '/inc/theme-settings/assets/css/settings.css', array(), $news_portal_version );
}
/**
* Enqueue scripts.
*/
public function about_theme_scripts( $hook ) {
global $news_portal_version;
$theme_notice_option = get_option( 'news_portal_admin_notice_welcome' );
if ( $theme_notice_option ) {
wp_enqueue_script( 'mt-theme-review-notice', get_template_directory_uri() . '/inc/theme-settings/assets/js/theme-review-notice.js', array( 'jquery' ), esc_attr( $news_portal_version ) );
$demo_importer_plugin = WP_PLUGIN_DIR . '/mysterythemes-demo-importer/mysterythemes-demo-importer.php';
if ( file_exists( $demo_importer_plugin ) && !is_plugin_active( 'mysterythemes-demo-importer/mysterythemes-demo-importer.php' ) ) {
$action = 'activate';
} elseif ( !file_exists( $demo_importer_plugin ) ) {
$action = 'install';
} else {
$action = 'redirect';
}
wp_localize_script( 'mt-theme-review-notice', 'mtaboutObject', array(
'ajax_url' => esc_url( admin_url( 'admin-ajax.php' ) ),
'_wpnonce' => wp_create_nonce( 'news_portal_admin_plugin_install_nonce' ),
'action' => esc_html( $action )
));
}
if ( 'appearance_page_news-portal-settings' != $hook ) {
return;
}
$activated_plugins = apply_filters( 'news_portal_active_plugins', get_option('active_plugins') );
$demo_import_plugin = in_array( 'mysterythemes-demo-importer/mysterythemes-demo-importer.php', $activated_plugins );
if ( $demo_import_plugin ) {
return;
}
wp_enqueue_script( 'mt-theme-settings-script', get_template_directory_uri() . '/inc/theme-settings/assets/js/settings.js', array( 'jquery' ), esc_attr( $news_portal_version ) );
$demo_importer_plugin = WP_PLUGIN_DIR . '/mysterythemes-demo-importer/mysterythemes-demo-importer.php';
if ( file_exists( $demo_importer_plugin ) && !is_plugin_active( 'mysterythemes-demo-importer/mysterythemes-demo-importer.php' ) ) {
$action = 'activate';
} else {
$action = 'install';
}
wp_localize_script( 'mt-theme-settings-script', 'mtaboutObject', array(
'ajax_url' => esc_url( admin_url( 'admin-ajax.php' ) ),
'_wpnonce' => wp_create_nonce( 'news_portal_admin_plugin_install_nonce' ),
'action' => esc_html( $action )
));
}
/**
* Add admin notice.
*/
public function news_portal_admin_notice() {
if ( isset( $_GET['activated'] ) ) {
update_option( 'news_portal_admin_notice_welcome', true );
}
$theme_notice_option = get_option( 'news_portal_admin_notice_welcome' );
// Let's bail on theme activation.
if ( $theme_notice_option ) {
add_action( 'admin_notices', array( $this, 'welcome_notice' ) );
}
}
/**
* Hide a notice if the GET variable is set.
*/
public static function news_portal_hide_notices() {
if ( isset( $_GET['news-portal-hide-notice'] ) && isset( $_GET['_news_portal_notice_nonce'] ) ) {
if ( ! wp_verify_nonce( $_GET['_news_portal_notice_nonce'], 'news_portal_hide_notices_nonce' ) ) {
wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'news-portal' ) );
}
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'Cheat in ’ huh?', 'news-portal' ) );
}
$hide_notice = sanitize_text_field( $_GET['news-portal-hide-notice'] );
update_option( 'news_portal_admin_notice_' . $hide_notice, false );
}
}
/**
* Show welcome notice.
*/
public function welcome_notice() {
$theme = wp_get_theme( get_template() );
$theme_name = $theme->get( 'Name' );
?>
'. esc_html( $theme_name ).'', '', ' ' ); ?>
', '' ); ?>
get( 'Name' );
$author_uri = $theme->get( 'AuthorURI' );
$author_name = $theme->get( 'Author' );
// Drop minor version if 0
?>
%2$s', 'news-portal' ), $author_uri, $author_name ); ?>
{ $current_tab . '_screen' }();
}
// Fallback to about screen.
return $this->about_screen();
}
/**
* Output the about screen.
*/
public function about_screen() {
$theme = wp_get_theme( get_template() );
$theme_name = $theme->template;
$doc_url = 'https://docs.mysterythemes.com/'. $theme_name;
$pro_theme_url = 'https://mysterythemes.com/wp-themes/'. $theme_name .'-pro/';
$support_url = 'https://wordpress.org/support/theme/'. $theme_name;
$review_url = 'https://wordpress.org/support/theme/'. $theme_name .'/reviews/#new-post';
?>
intro(); ?>
install_demo_import_plugin_popup(); ?>
intro(); ?>
get_contents( $changelog_file );
$changelog_list = $this->parse_changelog( $changelog );
echo wp_kses_post( $changelog_list );
}
?>
';
foreach ( $changes as $index => $line ) {
$changelog .= wp_kses_post( preg_replace( '~(=\s*(\d+(?:\.\d+)+)\s*=|$)~Uis', '${1} ', $line ) );
}
$changelog .= '';
}
return wp_kses_post( $changelog );
}
/**
* Output the free vs pro screen.
*/
public function free_vs_pro_screen() {
?>
ID;
$ignored_notice = get_user_meta( $user_id, 'news_portal_ignore_theme_review_notice', true );
$ignored_notice_partially = get_user_meta( $user_id, 'mt_news_portal_ignore_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( 'news_portal_theme_installed_time' ) > strtotime( '- 15 cal_days_in_month(calendar, month, year)' ) ) || ( $ignored_notice_partially > time() ) || ( $ignored_notice ) ) {
return;
}
?>
' . esc_html( $current_user->display_name ) . ''
);
?>
ID;
/* If user clicks to ignore the notice, add that to their user meta */
if ( isset( $_GET['mt_news_portal_ignore_theme_review_notice'] ) && '0' == $_GET['mt_news_portal_ignore_theme_review_notice'] ) {
add_user_meta( $user_id, 'news_portal_ignore_theme_review_notice', 'true', true );
}
}
/**
* Function to remove the theme review notice partially as requested by the user.
*/
public function news_portal_ignore_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['mt_news_portal_ignore_theme_review_notice_partially'] ) && '0' == $_GET['mt_news_portal_ignore_theme_review_notice_partially'] ) {
update_user_meta( $user_id, 'mt_news_portal_ignore_theme_review_notice_partially', strtotime( '+ 7 days' ) );
}
}
/**
* Remove the data set after the theme has been switched to other theme.
*/
public function news_portal_theme_rating_notice_data_remove() {
global $current_user;
$user_id = $current_user->ID;
$theme_installed_time = get_option( 'news_portal_theme_installed_time' );
$ignored_notice = get_user_meta( $user_id, 'news_portal_ignore_theme_review_notice', true );
$ignored_notice_partially = get_user_meta( $user_id, 'mt_news_portal_ignore_theme_review_notice_partially', true );
// Delete options data.
if ( $theme_installed_time ) {
delete_option( 'news_portal_theme_installed_time' );
}
// Delete permanent notice remove data.
if ( $ignored_notice ) {
delete_user_meta( $user_id, 'news_portal_ignore_theme_review_notice' );
}
// Delete partial notice remove data.
if ( $ignored_notice_partially ) {
delete_user_meta( $user_id, 'mt_news_portal_ignore_theme_review_notice_partially' );
}
}
/**
* Display custom text on theme settings page
*
* @param string $text
*/
public function news_portal_admin_footer_text( $text ) {
$screen = get_current_screen();
if ( 'appearance_page_news-portal-settings' == $screen->id ) {
$theme = wp_get_theme( get_template() );
$theme_name = $theme->get( 'Name' );
$text = sprintf( __( 'If you like %1$s please leave us a %2$s rating. A huge thank you from Mystery Themes in advance 😃!', 'news-portal' ), esc_html( $theme_name ), '★★★★★ ' );
}
return $text;
}
/**
* Popup alert for mystery themes demo importer plugin install.
*
* @since 1.2.0
*/
public function install_demo_import_plugin_popup() {
$demo_importer_plugin = WP_PLUGIN_DIR . '/mysterythemes-demo-importer/mysterythemes-demo-importer.php';
?>
false,
'message' => $result->get_error_message(),
)
);
} else {
wp_send_json_success(
array(
'success' => true,
'message' => __( 'Plugin Successfully Activated.', 'news-portal' ),
)
);
}
}
/**
* Activate Demo Importer Plugins Ajax Method
*
* @since 1.2.0
*/
function install_demo_importer_plugin() {
if ( ! wp_verify_nonce( $_POST['_wpnonce'], 'news_portal_admin_plugin_install_nonce' ) ) {
die( 'This action was stopped for security purposes.' );
}
if ( ! current_user_can( 'install_plugins' ) ) {
$status['message'] = __( 'Sorry, you are not allowed to install plugins on this site.', 'news-portal' );
wp_send_json_error( $status );
}
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
$api = plugins_api(
'plugin_information',
array(
'slug' => esc_html( 'mysterythemes-demo-importer' ),
'fields' => array(
'sections' => false,
),
)
);
if ( is_wp_error( $api ) ) {
$status['message'] = $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['message'] = $result->get_error_message();
wp_send_json_error( $status );
} elseif ( is_wp_error( $skin->result ) ) {
$status['errorCode'] = $skin->result->get_error_code();
$status['message'] = $skin->result->get_error_message();
wp_send_json_error( $status );
} elseif ( $skin->get_errors()->get_error_code() ) {
$status['message'] = $skin->get_error_messages();
wp_send_json_error( $status );
} elseif ( is_null( $result ) ) {
global $wp_filesystem;
$status['errorCode'] = 'unable_to_connect_to_filesystem';
$status['message'] = __( 'Unable to connect to the filesystem. Please confirm your credentials.', 'news-portal' );
// 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['message'] = esc_html( $wp_filesystem->errors->get_error_message() );
}
wp_send_json_error( $status );
}
if ( current_user_can( 'activate_plugin' ) ) {
$result = activate_plugin( '/mysterythemes-demo-importer/mysterythemes-demo-importer.php' );
if ( is_wp_error( $result ) ) {
$status['errorCode'] = $result->get_error_code();
$status['message'] = $result->get_error_message();
wp_send_json_error( $status );
}
}
$status['message'] = esc_html__( 'Plugin installed successfully', 'news-portal' );
wp_send_json_success( $status );
}
}
endif;
return new News_Portal_Settings();