Skip to content

Commit

Permalink
Merge branch '2.9' into awesomemotive#1820
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeltorbert committed Oct 11, 2018
2 parents e2ca517 + dd7cbbc commit 390cd8c
Show file tree
Hide file tree
Showing 5 changed files with 2,704 additions and 2,635 deletions.
64 changes: 50 additions & 14 deletions admin/aioseop_module_class.php
Expand Up @@ -1717,6 +1717,8 @@ function add_help_text_links() {
* edit-tags exists only for pre 4.5 support... remove when we drop 4.5 support.
* Also, that check and others should be pulled out into their own functions.
*
* @todo is it possible to migrate this to \All_in_One_SEO_Pack_Module::add_page_hooks? Or refactor? Both function about the same.
*
* @since 2.4.14 Added term as screen base.
*/
function enqueue_metabox_scripts() {
Expand Down Expand Up @@ -1757,22 +1759,27 @@ function enqueue_metabox_scripts() {
$enqueue_scripts = apply_filters( $prefix . 'enqueue_metabox_scripts', $enqueue_scripts, $screen, $v );
if ( $enqueue_scripts ) {
add_filter( 'aioseop_localize_script_data', array( $this, 'localize_script_data' ) );
add_action( 'admin_print_scripts', array( $this, 'enqueue_scripts' ), 20 );
add_action( 'admin_print_scripts', array( $this, 'enqueue_styles' ), 20 );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ), 20 );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_styles' ), 20 );
}
}
}
}

function admin_enqueue_scripts() {
wp_enqueue_media(); // WP 3.5+ Media upload.
}

/**
* Load styles for module.
*
* Add hook in \All_in_One_SEO_Pack_Module::enqueue_metabox_scripts - Bails adding hook if not on target valid screen.
* Add hook in \All_in_One_SEO_Pack_Module::add_page_hooks - Function itself is hooked based on the screen_id/page.
*
* @since 2.9
*
* @see 'admin_enqueue_scripts' hook
* @link https://developer.wordpress.org/reference/hooks/admin_enqueue_scripts/
*
* @param string $hook_suffix
*/
function enqueue_styles() {
function admin_enqueue_styles( $hook_suffix ) {
wp_enqueue_style( 'thickbox' );
if ( ! empty( $this->pointers ) ) {
wp_enqueue_style( 'wp-pointer' );
Expand All @@ -1784,27 +1791,56 @@ function enqueue_styles() {
}

/**
* Load scripts for module, can pass data to module script.
* Admin Enqueue Scripts
*
* Hook function to enqueue scripts and localize data to scripts.
*
* Add hook in \All_in_One_SEO_Pack_Module::enqueue_metabox_scripts - Bails adding hook if not on target valid screen.
* Add hook in \All_in_One_SEO_Pack_Module::add_page_hooks - Function itself is hooked based on the screen_id/page.
*
* @since ?
* @since 2.3.12.3 Add missing wp_enqueue_media.
* @since 2.9 Switch to admin_enqueue_scripts; both the hook and function name.
*
* @see 'admin_enqueue_scripts' hook
* @link https://developer.wordpress.org/reference/hooks/admin_enqueue_scripts/
* @global WP_Post $post Used to set the post ID in wp_enqueue_media().
*
* @param string $hook_suffix
*/
function enqueue_scripts() {
public function admin_enqueue_scripts( $hook_suffix ) {
wp_enqueue_script( 'sack' );
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'media-upload' );
wp_enqueue_script( 'thickbox' );
wp_enqueue_script( 'common' );
wp_enqueue_script( 'wp-lists' );
wp_enqueue_script( 'postbox' );

if ( ! empty( $this->pointers ) ) {
wp_enqueue_script( 'wp-pointer', false, array( 'jquery' ) );
wp_enqueue_script(
'wp-pointer',
false,
array( 'jquery' )
);
}

global $post;
if ( ! empty( $post->ID ) ) {
wp_enqueue_media( array( 'post' => $post->ID ) );
} else {
wp_enqueue_media();
}
wp_enqueue_script( 'aioseop-module-script', AIOSEOP_PLUGIN_URL . 'js/modules/aioseop_module.js', array(), AIOSEOP_VERSION );

// AIOSEOP Script enqueue.
wp_enqueue_script(
'aioseop-module-script',
AIOSEOP_PLUGIN_URL . 'js/modules/aioseop_module.js',
array(),
AIOSEOP_VERSION
);

// Localize aiosp_data in JS.
if ( ! empty( $this->script_data ) ) {
aioseop_localize_script_data();
}
Expand Down Expand Up @@ -1869,8 +1905,8 @@ function add_page_hooks() {
if ( $this->strpos( $hookname, 'load-' ) === 0 ) {
$this->pagehook = $this->substr( $hookname, 5 );
}
add_action( 'admin_print_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'admin_print_styles', array( $this, 'enqueue_styles' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_styles' ) );
add_filter( 'aioseop_localize_script_data', array( $this, 'localize_script_data' ) );
add_action( $this->prefix . 'settings_header', array( $this, 'display_tabs' ) );
}
Expand Down Expand Up @@ -2021,7 +2057,7 @@ function add_menu( $parent_slug ) {
$this->setting_options( $k ); // hack -- make sure this runs anyhow, for now -- pdb
$this->toggle_save_post_hooks( true );
if ( isset( $v['display'] ) && ! empty( $v['display'] ) ) {
add_action( 'admin_print_scripts', array( $this, 'enqueue_metabox_scripts' ), 5 );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_metabox_scripts' ), 5 );
if ( $this->tabbed_metaboxes ) {
add_filter( 'aioseop_add_post_metabox', array( $this, 'filter_return_metaboxes' ) );
}
Expand Down
33 changes: 25 additions & 8 deletions aioseop_class.php
Expand Up @@ -3282,22 +3282,39 @@ function settings_page_init() {
add_filter( "{$this->prefix}submit_options", array( $this, 'filter_submit' ) );
}

/**
* Admin Enqueue Styles All (Screens)
*
* Enqueue style on all admin screens.
*
* @since 2.9
*
* @param $hook_suffix
*/
public function admin_enqueue_styles_all( $hook_suffix ) {
wp_enqueue_style(
'aiosp_admin_style',
AIOSEOP_PLUGIN_URL . 'css/aiosp_admin.css',
array(),
AIOSEOP_VERSION
);
}

/**
* Admin Enqueue Scripts
*
* @since 2.5.0
* @since 2.9 Refactor code to `admin_enqueue_scripts` hook, and move enqueue stylesheet to \All_in_One_SEO_Pack::admin_enqueue_styles_all().
*
* @uses All_in_One_SEO_Pack_Module::admin_enqueue_scripts();
*
* @param string $hook_suffix
*/
function admin_enqueue_scripts() {
wp_enqueue_style( 'aiosp_admin_style', AIOSEOP_PLUGIN_URL . 'css/aiosp_admin.css', array(), AIOSEOP_VERSION );
parent::admin_enqueue_scripts();
}

function enqueue_scripts() {
public function admin_enqueue_scripts( $hook_suffix ) {
add_filter( "{$this->prefix}display_settings", array( $this, 'filter_settings' ), 10, 3 );
add_filter( "{$this->prefix}display_options", array( $this, 'filter_options' ), 10, 2 );
parent::enqueue_scripts();

parent::admin_enqueue_scripts( $hook_suffix );
}

/**
Expand Down Expand Up @@ -3699,7 +3716,7 @@ function add_hooks() {
add_action( 'admin_menu', array( $this, 'admin_menu' ) );

add_action( 'admin_head', array( $this, 'add_page_icon' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_styles_all' ) );
add_action( 'admin_init', 'aioseop_addmycolumns', 1 );
add_action( 'admin_init', 'aioseop_handle_ignore_notice' );
if ( AIOSEOPPRO ) {
Expand Down
7 changes: 7 additions & 0 deletions inc/aioseop_functions.php
Expand Up @@ -876,6 +876,13 @@ function aioseop_add_contactmethods( $contactmethods ) {

if ( ! function_exists( 'aioseop_localize_script_data' ) ) {

/**
* AIOSEOP Localize Script Data
*
* Used by the module base class script enqueue to localize data.
*
* @since ?
*/
function aioseop_localize_script_data() {
static $loaded = 0;
if ( ! $loaded ) {
Expand Down

0 comments on commit 390cd8c

Please sign in to comment.