'send-attachment-to-editor', */ if ( 'checked' === MLACore::mla_get_option( MLACoreOptions::MLA_MEDIA_MODAL_APPLY_DISPLAY_SETTINGS ) ) { $image_default_align = get_option( 'image_default_align' ); $image_default_link_type = get_option( 'image_default_link_type' ); $image_default_size = get_option( 'image_default_size' ); if ( ! ( empty( $image_default_align ) && empty( $image_default_link_type ) && empty( $image_default_size ) ) ) { $user_id = get_current_user_id(); $not_super_admin = ! (is_super_admin() && ! is_user_member_of_blog() ); if ( $user_id && $not_super_admin ) { if ( isset( $_COOKIE['wp-settings-' . $user_id] ) ) { $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user_id] ); } else { $cookie = (string) get_user_option( 'user-settings', $user_id ); } parse_str( $cookie, $cookie_array ); $cookie_align = isset( $cookie_array['align'] ) ? $cookie_array['align'] : ''; $cookie_urlbutton = isset( $cookie_array['urlbutton'] ) ? $cookie_array['urlbutton'] : ''; $cookie_imgsize = isset( $cookie_array['imgsize'] ) ? $cookie_array['imgsize'] : ''; $changed = false; if ( ( ! empty( $image_default_align ) ) && ( $cookie_align !== $image_default_align ) ) { $cookie_array['align'] = $image_default_align; $changed = true; } if ( ( ! empty( $image_default_link_type ) ) && ( $cookie_urlbutton !== $image_default_link_type ) ) { $cookie_array['urlbutton'] = $image_default_link_type; $changed = true; } if ( ( ! empty( $image_default_size ) ) && ( $cookie_imgsize !== $image_default_size ) ) { $cookie_array['imgsize'] = $image_default_size; $changed = true; } if ( $changed ) { $cookie = http_build_query( $cookie_array, '', '&' ); $current = time(); $secure = ( 'https' === parse_url( admin_url(), PHP_URL_SCHEME ) ); setcookie( 'wp-settings-' . $user_id, $cookie, time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure ); setcookie( 'wp-settings-time-' . $user_id, $current, $current + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure ); $_COOKIE['wp-settings-' . $user_id] = $cookie; $_COOKIE['wp-settings-time-' . $user_id] = $current; } } } } // MLA_MEDIA_MODAL_APPLY_DISPLAY_SETTINGS // Hook wp_enqueue_media() so we can add MLA enhancements, if requested if ( 'checked' == MLACore::mla_get_option( MLACoreOptions::MLA_MEDIA_MODAL_TOOLBAR ) ) { add_filter( 'media_view_settings', 'MLACore::mla_media_view_settings_filter', 10, 2 ); } } /** * Ensures that MLA media manager enhancements are present when required. * Declared public because it is a filter. * * @since 2.30 * * @param array associative array with setting => value pairs * @param object || NULL current post object, if available */ public static function mla_media_view_settings_filter( $settings, $post ) { if ( class_exists( 'MLAModal' ) ) { return $settings; } // Visual Composer template preview doesn't need MLA enhancements if ( defined( 'VC_IS_TEMPLATE_PREVIEW' ) ) { return $settings; } // Media Manager (Modal window) additions if ( !class_exists( 'MLAQuery' ) ) { require_once( MLA_PLUGIN_PATH . 'includes/class-mla-data-query.php' ); MLAQuery::initialize(); } if ( !class_exists( 'MLAData' ) ) { require_once( MLA_PLUGIN_PATH . 'includes/class-mla-data.php' ); MLAData::initialize(); } require_once( MLA_PLUGIN_PATH . 'includes/class-mla-list-table.php' ); require_once( MLA_PLUGIN_PATH . 'includes/class-mla-media-modal.php' ); MLAModal::initialize(); add_action( 'wp_enqueue_media', 'MLACore::mla_wp_enqueue_media_action', 10, 0 ); return MLAModal::mla_media_view_settings_filter( $settings, $post ); } /** * Registers and enqueues the mla-beaver-builder-style.css file, when needed. * Declared public because it is an action. * * @since 2.30 */ public static function mla_wp_enqueue_media_action( ) { global $wp_locale; if ( $wp_locale->is_rtl() ) { wp_register_style( MLAModal::JAVASCRIPT_MEDIA_MODAL_STYLES . '-bb', MLA_PLUGIN_URL . 'css/mla-beaver-builder-style-rtl.css', false, MLACore::CURRENT_MLA_VERSION ); } else { wp_register_style( MLAModal::JAVASCRIPT_MEDIA_MODAL_STYLES . '-bb', MLA_PLUGIN_URL . 'css/mla-beaver-builder-style.css', false, MLACore::CURRENT_MLA_VERSION ); } wp_enqueue_style( MLAModal::JAVASCRIPT_MEDIA_MODAL_STYLES . '-bb' ); } // mla_wp_enqueue_media_action /** * Add the WPML suppress All languages filter * * The "add_action" for this function is in mla-plugin-loader.php, because the "initialize" * function above doesn't run in time. * Defined as public because it's an action. * * @since 2.32 * * @return void */ public static function mla_plugins_loaded_action_wpml(){ // Defined in /sitepress-multilingual-cms/sitepress.class.php add_filter( 'wpml_unset_lang_admin_bar', 'MLACore::wpml_unset_lang_admin_bar', 10, 1 ); } // mla_plugins_loaded_action_wpml /** * Restores All languages view to Media/Assistant submenu screen * * @since 2.32 * * @param boolean true to suppress All languages, false to allow it */ public static function wpml_unset_lang_admin_bar( $suppress_all_languages ) { global $pagenow, $mode; return $pagenow === 'upload.php' && $mode === 'grid'; } /** * Load a plugin text domain and alternate debug file * * The "add_action" for this function is in mla-plugin-loader.php, because the "initialize" * function above doesn't run in time. * Defined as public because it's an action. * * @since 1.60 * * @return void */ public static function mla_plugins_loaded_action(){ $text_domain = 'media-library-assistant'; $locale = function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); $locale = apply_filters( 'mla_plugin_locale', $locale, $text_domain ); if ( is_admin() && 'en_US' === $locale ) { $result = unload_textdomain( $text_domain ); } /* * To override the plugin's translation files for one, some or all strings, * create a sub-directory named 'media-library-assistant' in the WordPress * WP_LANG_DIR (e.g., /wp-content/languages) directory. */ load_textdomain( $text_domain, trailingslashit( WP_LANG_DIR ) . $text_domain . '/' . $text_domain . '-' . $locale . '.mo' ); load_plugin_textdomain( $text_domain, false, MLA_PLUGIN_BASENAME . '/languages/' ); // This must/will be repeated in class-mla-tests.php to reflect translations MLACoreOptions::mla_localize_option_definitions_array(); MLACore::$original_php_log = ini_get( 'error_log' ); MLACore::$original_php_reporting = sprintf( '0x%1$04X', error_reporting() ); // Do not process debug options unless MLA_DEBUG_LEVEL is set in wp-config.php if ( MLA_DEBUG_LEVEL & 1 ) { // Set up alternate MLA debug log file $error_log_name = MLACore::mla_get_option( MLACoreOptions::MLA_DEBUG_FILE ); if ( ! empty( $error_log_name ) ) { MLACore::mla_debug_file( $error_log_name ); // Override PHP error_log file if ( 'checked' === MLACore::mla_get_option( MLACoreOptions::MLA_DEBUG_REPLACE_PHP_LOG ) ) { $result = ini_set('error_log', WP_CONTENT_DIR . self::$mla_debug_file ); } } /* * PHP error_reporting must be done later in class-mla-tests.php * Override MLA debug levels */ MLACore::$mla_debug_level = 0; // MLA_DEBUG_LEVEL; $mla_reporting = trim( MLACore::mla_get_option( MLACoreOptions::MLA_DEBUG_REPLACE_LEVEL ) ); if ( strlen( $mla_reporting ) ) { if ( ctype_digit( $mla_reporting ) ) { $mla_reporting = intval( $mla_reporting ); } else{ $mla_reporting = hexdec( $mla_reporting ); } if ( $mla_reporting ) { MLACore::$mla_debug_level = $mla_reporting | 1; if ( class_exists( 'MLA' ) && ! ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] === 'heartbeat' ) ) { MLACore::mla_debug_add( __LINE__ . sprintf( ' MLACore::mla_plugins_loaded_action() MLA %s (%s) mla_debug_level 0x%X', MLACore::CURRENT_MLA_VERSION, MLA::MLA_DEVELOPMENT_VERSION, MLACore::$mla_debug_level, true ), MLACore::MLA_DEBUG_CATEGORY_ANY ); } } else { MLACore::$mla_debug_level = 0; } } // Check for XMLPRC, WP REST API and front end requests if( !( defined('WP_ADMIN') && WP_ADMIN ) ) { // XMLRPC requests need everything loaded to process uploads if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST ) { MLACore::mla_debug_add( __LINE__ . " MLACore::mla_plugins_loaded_action() XMLRPC_REQUEST \$_REQUEST = " . var_export( $_REQUEST, true ), MLACore::MLA_DEBUG_CATEGORY_ANY ); } // WP REST API calls need everything loaded to process uploads if ( isset( $_SERVER['REQUEST_URI'] ) && 0 === strpos( $_SERVER['REQUEST_URI'], '/wp-json/' ) ) { MLACore::mla_debug_add( __LINE__ . " MLACore::mla_plugins_loaded_action() wp-json REQUEST_URI = " . var_export( $_SERVER['REQUEST_URI'], true ), MLACore::MLA_DEBUG_CATEGORY_REST ); //MLACore::mla_debug_add( __LINE__ . " MLACore::mla_plugins_loaded_action() wp-json _GET = " . var_export( $_GET, true ), MLACore::MLA_DEBUG_CATEGORY_REST ); //MLACore::mla_debug_add( __LINE__ . " MLACore::mla_plugins_loaded_action() wp-json _POST = " . var_export( $_POST, true ), MLACore::MLA_DEBUG_CATEGORY_REST ); MLACore::mla_debug_add( __LINE__ . " MLACore::mla_plugins_loaded_action() wp-json _REQUEST = " . var_export( $_REQUEST, true ), MLACore::MLA_DEBUG_CATEGORY_REST ); MLACore::mla_debug_add( __LINE__ . " MLACore::mla_plugins_loaded_action() wp-json _COOKIE = " . var_export( $_COOKIE, true ), MLACore::MLA_DEBUG_CATEGORY_REST ); if ( function_exists( 'apache_request_headers' ) ) { MLACore::mla_debug_add( __LINE__ . " MLACore::mla_plugins_loaded_action() wp-json MLAOptions apache_request_headers = " . var_export( apache_request_headers(), true ), MLACore::MLA_DEBUG_CATEGORY_REST ); } MLACore::mla_debug_add( __LINE__ . " MLACore::mla_plugins_loaded_action() wp-json MLAOptions exists = " . var_export( class_exists( 'MLAOptions' ), true ), MLACore::MLA_DEBUG_CATEGORY_REST ); } } // not admin } // MLA_DEBUG_LEVEL & 1 } /** * Create a NONCE URL that works in WP 3.5.x and later * * @since 2.71 * * @param string $actionurl URL to add nonce action. * @param string $action Optional. Nonce action name. Default -1. * @param string $name Optional. Nonce name. Default '_wpnonce'. * * @return string Escaped URL with nonce action added. */ public static function mla_nonce_url( $actionurl, $action = -1, $name = '_wpnonce' ) { $actionurl = wp_nonce_url( $actionurl, $action, $name ); // WP 3.5.x wp_nonce_url() does not accept the third NONCE name argument if ( '_wpnonce' !== $name ) { $actionurl = str_replace( '_wpnonce', $name, $actionurl ); } return $actionurl; } /** * Filter the redirect location. * * @since 2.25 * * @param string $location The path to redirect to. * @param int $status Status code to use. */ public static function mla_wp_redirect_filter( $location, $status ) { /* * Check for Update, Trash or Delete Permanently on Media/Edit Media screen, */ if ( ( false !== strpos( $location, 'upload.php?' ) ) || ( false !== strpos( $location, 'post.php?' ) ) ) { $location = add_query_arg( array( 'mla_source' => $_REQUEST['mla_source'] ), $location ); } return $location; } /** * Initialize "tax_checked_on_top" => "checked" default for all supported taxonomies * * Called after all taxonomies are registered, e.g., in MLAObjects::_build_taxonomies. * * @since 2.02 * * @return void */ public static function mla_initialize_tax_checked_on_top() { if ( NULL === MLACoreOptions::$mla_option_definitions[ MLACoreOptions::MLA_TAXONOMY_SUPPORT ]['std']['tax_checked_on_top'] ) { /* * WordPress default is 'checked_ontop' => true * Initialize tax_checked_on_top defaults to true for all supported taxonomies */ $checked_on_top = array(); $taxonomies = MLACore::mla_supported_taxonomies(); foreach ( $taxonomies as $new_key ) { $checked_on_top[ $new_key ] = 'checked'; } MLACoreOptions::$mla_option_definitions[ MLACoreOptions::MLA_TAXONOMY_SUPPORT ]['std']['tax_checked_on_top'] = $checked_on_top; } } /** * Return the stored value or default value of a defined MLA option * * @since 2.20 * * @param string Name of the desired option * @param boolean True to ignore current setting and return default values * @param boolean True to ignore default values and return only stored values * @param array Custom option definitions * * * @return mixed Value(s) for the option or false if the option is not a defined MLA option */ public static function mla_get_option( $option, $get_default = false, $get_stored = false, &$option_table = NULL ) { if ( NULL == $option_table ) { if ( empty( MLACoreOptions::$mla_option_definitions ) ) { MLACoreOptions::mla_localize_option_definitions_array(); } $option_table =& MLACoreOptions::$mla_option_definitions; } if ( ! array_key_exists( $option, $option_table ) ) { return false; } if ( $get_default ) { if ( array_key_exists( 'std', $option_table[ $option ] ) ) { return $option_table[ $option ]['std']; } return false; } // $get_default if ( ! $get_stored && array_key_exists( 'std', $option_table[ $option ] ) ) { return get_option( MLA_OPTION_PREFIX . $option, $option_table[ $option ]['std'] ); } return get_option( MLA_OPTION_PREFIX . $option, false ); } /** * Add or update the stored value of a defined MLA option * * @since 2.20 * * @param string Name of the desired option * @param mixed New value for the desired option * @param array Custom option definitions * * @return boolean True if the value was changed or false if the update failed */ public static function mla_update_option( $option, $newvalue, &$option_table = NULL ) { if ( NULL == $option_table ) { if ( empty( MLACoreOptions::$mla_option_definitions ) ) { MLACoreOptions::mla_localize_option_definitions_array(); } $option_table =& MLACoreOptions::$mla_option_definitions; } if ( array_key_exists( $option, $option_table ) ) { if ( isset( $option_table[ $option ]['autoload'] ) ) { $autoload = (boolean) $option_table[ $option ]['autoload']; } else { $autoload = true; } return update_option( MLA_OPTION_PREFIX . $option, $newvalue, $autoload ); } return false; } /** * Delete the stored value of a defined MLA option * * @since 2.20 * * @param string Name of the desired option * @param array Custom option definitions * * @return boolean True if the option was deleted, otherwise false */ public static function mla_delete_option( $option, &$option_table = NULL ) { if ( NULL == $option_table ) { if ( empty( MLACoreOptions::$mla_option_definitions ) ) { MLACoreOptions::mla_localize_option_definitions_array(); } $option_table =& MLACoreOptions::$mla_option_definitions; } if ( array_key_exists( $option, $option_table ) ) { return delete_option( MLA_OPTION_PREFIX . $option ); } return false; } /** * Load an HTML template from a file * * Loads a template to a string or a multi-part template to an array. * Multi-part templates are divided by comments of the form , * where "key" becomes the key part of the array. * * @since 0.1 * * @param string Complete path and/or name of the template file, option name or the raw template * @param string Optional type of template source; 'path', 'file' (default), 'option', 'string' * * @return string|array|false|NULL * string for files that do not contain template divider comments, * array for files containing template divider comments, * false if file or option does not exist, * NULL if file could not be loaded. */ public static function mla_load_template( $source, $type = 'file' ) { switch ( $type ) { case 'file': /* * Look in three places, in this order: * 1) Custom templates * 2) Language-specific templates * 3) Standard templates */ $text_domain = 'media-library-assistant'; $locale = apply_filters( 'mla_plugin_locale', get_locale(), $text_domain ); $path = trailingslashit( WP_LANG_DIR ) . $text_domain . '/tpls/' . $locale . '/' . $source; if ( file_exists( $path ) ) { $source = $path; } else { $path = MLA_PLUGIN_PATH . 'languages/tpls/' . $locale . '/' . $source; if ( file_exists( $path ) ) { $source = $path; } else { $source = MLA_PLUGIN_PATH . 'tpls/' . $source; } } // fallthru case 'path': if ( !file_exists( $source ) ) { return false; } $template = file_get_contents( $source, true ); if ( $template == false ) { /* translators: 1: ERROR tag 2: path and file name */ MLACore::mla_debug_add( sprintf( _x( '%1$s: mla_load_template file "%2$s" not found.', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), var_export( $source, true ) ), MLACore::MLA_DEBUG_CATEGORY_ANY ); return NULL; } break; case 'option': $template = MLACore::mla_get_option( $source ); if ( $template == false ) { return false; } break; case 'string': $template = $source; if ( empty( $template ) ) { return false; } break; default: /* translators: 1: ERROR tag 2: path and file name 3: source type, e.g., file, option, string */ MLACore::mla_debug_add( sprintf( _x( '%1$s: mla_load_template file "%2$s" bad source type "%3$s".', 'error_log', 'media-library-assistant' ), __( 'ERROR', 'media-library-assistant' ), $source, $type ), MLACore::MLA_DEBUG_CATEGORY_ANY ); return NULL; } $match_count = preg_match_all( '#\