Skip to content

Commit

Permalink
Merge branch 'wp.org' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ideadude committed Oct 26, 2018
2 parents a30d979 + 281e498 commit af6644a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 296 deletions.
146 changes: 18 additions & 128 deletions inc/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,6 @@ function memberlite_theme_menu() {
}
add_action( 'admin_menu', 'memberlite_theme_menu' );

/*
Redirect to Welcome tab if the user hasn't been there yet.
*/
function memberlite_admin_init_redirect_to_welcome() {
$memberlite_welcome_version = get_option( 'memberlite_welcome_version', 0 );
if (version_compare( $memberlite_welcome_version, MEMBERLITE_VERSION) < 0 ) {
update_option( 'memberlite_welcome_version', MEMBERLITE_VERSION, 'no' );
wp_redirect( admin_url( 'admin.php?page=memberlite-support' ) );
exit;
}
}
add_action( 'admin_init', 'memberlite_admin_init_redirect_to_welcome' );

/*
Render the welcome/support page
*/
Expand Down Expand Up @@ -340,8 +327,7 @@ function memberlite_support() {
/*
Load any notifications.
1. Prompt the installation of memberlite-shortcodes if it's not activated already.
2. Prompt the installation of pmpro-advanced-levels-shortcode if it's not activated already.
1. Show link to the welcome page the first time the theme is activated
*/
// check for notifications
function memberlite_admin_init_notifications() {
Expand All @@ -351,51 +337,19 @@ function memberlite_admin_init_notifications() {
$script = basename( $_SERVER['SCRIPT_NAME'] );
$maybe_installing = $script == 'update.php' || $script == 'plugins.php';

// 1. Prompt the installation of memberlite-elements if it's not activated already.
if ( ! defined( 'MEMBERLITE_ELEMENTS_VERSION' ) && ! $maybe_installing ) {
// check if this notice has been dismissed already
$mle_dismissed = get_option( 'memberlite_notice_install_memberlite_elements_dismissed', false );
if ( ! $mle_dismissed ) {
wp_enqueue_script( 'memberlite-admin-dismiss-notice', get_template_directory_uri() . '/js/admin-dismiss-notice.js', array( 'jquery' ), MEMBERLITE_VERSION, true );
add_action( 'admin_notices', 'memberlite_admin_notice_install_memberlite_elements' );
}
}

// 2. Prompt the installation of memberlite-shortcodes if it's not activated already.
if ( ! defined( 'MEMBERLITESC_VERSION' ) && ! $maybe_installing ) {
// check if this notice has been dismissed already
$mls_dismissed = get_option( 'memberlite_notice_install_memberlite_shortcodes_dismissed', false );
if ( ! $mls_dismissed ) {
wp_enqueue_script( 'memberlite-admin-dismiss-notice', get_template_directory_uri() . '/js/admin-dismiss-notice.js', array( 'jquery' ), MEMBERLITE_VERSION, true );
add_action( 'admin_notices', 'memberlite_admin_notice_install_memberlite_shortcodes' );
}
}

// 3. Prompt the installation of pmpro-advanced-levels-shortcode if it's not activated already.
if ( ! function_exists( 'pmpro_advanced_levels_shortcode' ) && ! $maybe_installing ) {
// check if this notice has been dismissed already
$als_dismissed = get_option( 'memberlite_notice_install_advanced_levels_shortcode_dismissed', false );
if ( ! $als_dismissed ) {
// check if they are using the [memberlite_levels] shortcode
$using_shortcode = $wpdb->get_var( "SELECT ID FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish' AND post_content LIKE '%[memberlite_levels%' LIMIT 1" );

if ( $using_shortcode ) {
// show notice
wp_enqueue_script( 'memberlite-admin-dismiss-notice', get_template_directory_uri() . '/js/admin-dismiss-notice.js', array( 'jquery' ), MEMBERLITE_VERSION, true );
add_action( 'admin_notices', 'memberlite_admin_notice_install_advanced_levels_shortcode' );
} else {
// not using the shortcode, so let's just dismiss the notice
update_option( 'memberlite_notice_install_advanced_levels_shortcode_dismissed', 1, 'no' );
}
}
// 1. Show link to the welcome page the first time the theme is activated
$welcome_link_dismissed = get_option( 'memberlite_notice_welcome_link_dismissed', false );
if ( ! $welcome_link_dismissed && ! $maybe_installing ) {
wp_enqueue_script( 'memberlite-admin-dismiss-notice', get_template_directory_uri() . '/js/admin-dismiss-notice.js', array( 'jquery' ), MEMBERLITE_VERSION, true );
add_action( 'admin_notices', 'memberlite_admin_notice_welcome_link' );
}
}
add_action( 'admin_init', 'memberlite_admin_init_notifications' );

// AJAX to handle notice dismissal
function memberlite_wp_ajax_dismiss_notice() {
// whitelist of notices
$notices = array( 'install_advanced_levels_shortcode', 'install_memberlite_shortcodes' );
$notices = array( 'welcome_link' );

// get and check notice
$notice = $_REQUEST['notice'];
Expand All @@ -411,83 +365,19 @@ function memberlite_wp_ajax_dismiss_notice() {
add_action( 'wp_ajax_nopriv_memberlite_dismiss_notice', 'memberlite_wp_ajax_dismiss_notice' );
add_action( 'wp_ajax_memberlite_dismiss_notice', 'memberlite_wp_ajax_dismiss_notice' );

// Install Memberlite Elements Notice
function memberlite_admin_notice_install_memberlite_elements() {
// check if the plugin is installed, but not active
if ( file_exists( WP_PLUGIN_DIR . '/memberlite-elements/memberlite-elements.php' ) ) {
// installed but not activated
$click_link = esc_url( wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=memberlite-elements/memberlite-elements.php' ), 'activate-plugin_memberlite-elements/memberlite-elements.php' ) );
$click_text = __(
'Click here to activate the Memberlite Elements plugin.',
'memberlite'
);
} else {
// need to install
$click_link = esc_url( wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=memberlite-elements' ), 'install-plugin_memberlite-elements' ) );
$click_text = __(
'Click here to install the Memberlite Elements plugin.',
'memberlite'
);
}

// notice HTML
?>
<div id="memberlite-admin-notice-install_memberlite_elements" class="notice notice-error is-dismissible memberlite-notice">
<p><strong><?php esc_html_e( 'Memberlite', 'memberlite' ); ?>:</strong> <?php echo esc_html__( 'Some features of Memberlite now require the Memberlite Elements plugin.', 'memberlite' ) . ' <a href="' . $click_link . '">' . $click_text . '</a>'; ?></p>
</div>
<?php
}

// Install Memberlite Shortcodes Notice
function memberlite_admin_notice_install_memberlite_shortcodes() {
// check if the plugin is installed, but not active
if ( file_exists( WP_PLUGIN_DIR . '/memberlite-shortcodes/memberlite-shortcodes.php' ) ) {
// installed but not activated
$click_link = wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=memberlite-shortcodes/memberlite-shortcodes.php' ), 'activate-plugin_memberlite-shortcodes/memberlite-shortcodes.php' );
$click_text = __(
'Click here to activate the Memberlite Shortcodes plugin.',
'memberlite'
);
} else {
// need to install
$click_link = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=memberlite-shortcodes' ), 'install-plugin_memberlite-shortcodes' );
$click_text = __(
'Click here to install the Memberlite Shortcodes plugin.',
'memberlite'
);
}

// notice HTML
?>
<div id="memberlite-admin-notice-install_memberlite_shortcodes" class="notice notice-error is-dismissible memberlite-notice">
<p><strong><?php esc_html_e( 'Memberlite', 'memberlite' ); ?>:</strong> <?php echo esc_html__( 'Some features of Memberlite now require the Memberlite Shortcodes plugin.', 'memberlite' ) . ' <a href="' . $click_link . '">' . $click_text . '</a>'; ?></p>
</div>
<?php
}

// Install Advanced Levels Shortcode Notice
function memberlite_admin_notice_install_advanced_levels_shortcode() {
// check if the plugin is installed, but not active
if ( file_exists( WP_PLUGIN_DIR . '/pmpro-advanced-levels-shortcode/pmpro-advanced-levels-shortcode.php' ) ) {
// installed but not activated
$click_link = wp_nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=pmpro-advanced-levels-shortcode/pmpro-advanced-levels-shortcode.php' ), 'activate-plugin_pmpro-advanced-levels-shortcode/pmpro-advanced-levels-shortcode.php' );
$click_text = __(
'Click here to activate the Advanced Levels Shortcode plugin.',
'memberlite'
);
} else {
// need to install
$click_link = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=pmpro-advanced-levels-shortcode' ), 'install-plugin_pmpro-advanced-levels-shortcode' );
$click_text = __(
'Click here to install the Advanced Levels Shortcode plugin.',
'memberlite'
);
}

// Welcome Link Notice
function memberlite_admin_notice_welcome_link() {
// notice HTML
?>
<div id="memberlite-admin-notice-install_advanced_levels_shortcode" class="notice notice-error is-dismissible memberlite-notice">
<p><strong><?php esc_html_e( 'Memberlite', 'memberlite' ); ?>:</strong> <?php echo esc_html__( 'The [memberlite_levels] shortcode has been merged into the Advanced Levels Shortcode add on.', 'memberlite' ) . ' <a href="' . $click_link . '">' . $click_text . '</a>'; ?></p>
<div id="memberlite-admin-notice-welcome_link" class="notice notice-error is-dismissible memberlite-notice">
<p><strong><?php esc_html_e( 'Memberlite', 'memberlite' ); ?>:</strong>
<?php
echo esc_html__( "We have documentation and recommended plugins to help you get started with Memberlite Theme.", 'memberlite' );
$click_link = esc_url( add_query_arg( 'page', 'memberlite-support', admin_url( 'themes.php' ) ) );
$click_text = esc_html__( 'Click here to view the Memberlite welcome page.', 'memberlite' );
echo ' <a href="' . $click_link . '">' . $click_text . '</a>';
?>
</p>
</div>
<?php
}
2 changes: 1 addition & 1 deletion inc/custom-header.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function memberlite_custom_header_setup() {
)
);
}
add_action( 'after_setup_theme', 'memberlite_custom_header_setup' );
add_action('after_setup_theme', 'memberlite_custom_header_setup');

if ( ! function_exists( 'memberlite_header_style' ) ) :
/**
Expand Down
7 changes: 6 additions & 1 deletion inc/extras.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,12 @@ function memberlite_getPostThumbnailWidth( $post_id = null ) {
*/
function memberlite_excerpt_more( $more ) {
global $post;
return ' <a href="' . get_permalink( $post->ID ) . '" rel="nofollow">(more...)</a></p>';

if ( ! is_admin() ) {
$more = ' <a href="' . esc_url( get_permalink( $post->ID ) ) . '" rel="nofollow">' . esc_html( __( '(more...)', 'memberlite' ) ) . '</a>';
}

return $more;
}
add_filter( 'excerpt_more', 'memberlite_excerpt_more' );

Expand Down
169 changes: 3 additions & 166 deletions inc/updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,172 +9,9 @@
function memberlite_checkForUpdates() {
$memberlite_db_version = get_option('memberlite_db_version', 0);

/**
* Upgrade from v2.0.
*
*/
if($memberlite_db_version < '2016091901') {

/**
* We need to convert header images into site logos.
*/
$header_image_data = get_theme_mod('header_image_data');
$custom_logo = get_theme_mod('custom_logo');

if(!empty($header_image_data) && empty($custom_logo)) {
$custom_logo = $header_image_data->attachment_id;
set_theme_mod('custom_logo', $custom_logo);
remove_theme_mod('header_image');
remove_theme_mod('header_image_data');
}

/**
* We need to convert 'memberlite_show_image_banner' meta to '_memberlite_show_image_banner'.
*/
global $wpdb;
$sqlQuery = "UPDATE $wpdb->postmeta SET meta_key = '_memberlite_show_image_banner' WHERE meta_key = 'memberlite_show_image_banner'";
$wpdb->query($sqlQuery);

//update db version
$memberlite_db_version = '2016091901';
// default DB version for Memberlite 4.0
if( empty( $memberlite_db_version ) ) {
$memberlite_db_version = '2018080101';
update_option('memberlite_db_version', $memberlite_db_version, 'no');
}
}

/*
NOTE: All code below here will be removed once the theme is in the WordPress.org repository
*/

/**
* Setup themes api filters
*
* @since 2.0
*/
function memberlite_setupUpdateInfo()
{
if(!defined('PMPRO_LICENSE_SERVER'))
define('PMPRO_LICENSE_SERVER', 'http://license.paidmembershipspro.com');

add_filter('pre_set_site_transient_update_themes', 'memberlite_update_themes_filter');
add_filter('http_request_args', 'memberlite_http_request_args_for_update_info', 10, 2);
add_action('update_option_pmpro_license_key', 'memberlite_update_option_pmpro_license_key', 10, 2);
}
add_action('init', 'memberlite_setupUpdateInfo');
/**
* Get theme update information from the PMPro server.
*
* @since 2.0
*/
function memberlite_getUpdateInfo()
{
//check if forcing a pull from the server
$update_info = get_option("memberlite_update_info", false);
$update_info_timestamp = get_option("memberlite_update_info_timestamp", 0);

//if no update_infos locally, we need to hit the server
if(empty($update_info) || !empty($_REQUEST['force-check']) || current_time('timestamp') > $update_info_timestamp+86400)
{
/**
* Filter to change the timeout for this wp_remote_get() request.
*
* @since 2.0.1
*
* @param int $timeout The number of seconds before the request times out
*/
$timeout = apply_filters("memberlite_get_update_info_timeout", 5);
//get em
$remote_info = wp_remote_get(PMPRO_LICENSE_SERVER . "/themes/memberlite", $timeout);

//test response
if(is_wp_error($remote_info) || empty($remote_info['response']) || $remote_info['response']['code'] != '200')
{
//error
if(function_exists('pmpro_setMessage'))
pmpro_setMessage("Could not connect to the PMPro License Server to get update information. Try again later.", "error");
}
else
{
//update update_infos in cache
$update_info = json_decode(wp_remote_retrieve_body($remote_info), true);
delete_option('memberlite_update_info');
add_option("memberlite_update_info", $update_info, NULL, 'no');
}

//save timestamp of last update
delete_option('memberlite_update_info_timestamp');
add_option("memberlite_update_info_timestamp", current_time('timestamp'), NULL, 'no');
}

return $update_info;
}
/**
* Infuse theme update details when WordPress runs its update checker.
*
* @since 2.0
*
* @param object $value The WordPress update object.
* @return object $value Amended WordPress update object on success, default if object is empty.
*/
function memberlite_update_themes_filter( $value ) {

// If no update object exists, return early.
if ( empty( $value ) ) {
return $value;
}

// get update_info information
$update_info = memberlite_getUpdateInfo();

// no info?
if(empty($update_info))
return $value;

//get data for theme
$theme_file_abs = ABSPATH . 'wp-content/themes/' . $update_info['Slug'];
$theme_file = $theme_file_abs . "/style.css";
$theme_data = wp_get_theme($update_info['Slug']);
//compare versions
if(!empty($update_info['License']) && version_compare($theme_data['Version'], $update_info['Version'], '<'))
{
$value->response[$update_info['Slug']] = array(
'theme' => $update_info['Slug'],
'new_version' => $update_info['Version'],
'url' => $update_info['ThemeURI'],
'package' => $update_info['Download']
);
}

// Return the update object.
return $value;
}
/**
* Disables SSL verification to prevent download package failures.
*
* @since 2.0
*
* @param array $args Array of request args.
* @param string $url The URL to be pinged.
* @return array $args Amended array of request args.
*/
function memberlite_http_request_args_for_update_info($args, $url)
{
// If this is an SSL request and we are performing an upgrade routine, disable SSL verification.
if(strpos($url, 'https://') !== false && strpos($url, PMPRO_LICENSE_SERVER) !== false && strpos($url, "download") !== false)
$args['sslverify'] = false;

return $args;
}
/**
* Force update of theme update data when the PMPro License key is updated
*
* @since 2.0
*
* @param array $args Array of request args.
* @param string $url The URL to be pinged.
* @return array $args Amended array of request args.
*/
function memberlite_update_option_pmpro_license_key($old_value, $value)
{
delete_option('memberlite_update_info_timestamp');
delete_site_transient('update_themes');
}

0 comments on commit af6644a

Please sign in to comment.