' ) ) { /* * Convert attachment_category and _tag to taxonomy_support; * change the default if either option is unchecked */ $category_option = MLACore::mla_get_option( 'attachment_category' ); $tag_option = MLACore::mla_get_option( 'attachment_tag' ); if ( ! ( ( 'checked' == $category_option ) && ( 'checked' == $tag_option ) ) ) { $tax_option = MLACore::mla_get_option( MLACoreOptions::MLA_TAXONOMY_SUPPORT ); if ( 'checked' != $category_option ) { if ( isset( $tax_option['tax_support']['attachment_category'] ) ) { unset( $tax_option['tax_support']['attachment_category'] ); } } if ( 'checked' != $tag_option ) { if ( isset( $tax_option['tax_support']['attachment_tag'] ) ) { unset( $tax_option['tax_support']['attachment_tag'] ); } } MLAOptions::mla_taxonomy_option_handler( 'update', 'taxonomy_support', MLACoreOptions::$mla_option_definitions['taxonomy_support'], $tax_option ); } // one or both options unchecked MLACore::mla_delete_option( 'attachment_category' ); MLACore::mla_delete_option( 'attachment_tag' ); } // version is less than .30 if ( version_compare( '1.13', $current_version, '>' ) ) { /* * Add quick_edit and bulk_edit values to custom field mapping rules */ $new_values = array(); foreach ( MLACore::mla_get_option( 'custom_field_mapping' ) as $key => $value ) { $value['quick_edit'] = ( isset( $value['quick_edit'] ) && $value['quick_edit'] ) ? true : false; $value['bulk_edit'] = ( isset( $value['bulk_edit'] ) && $value['bulk_edit'] ) ? true : false; $new_values[ $key ] = $value; } MLACore::mla_update_option( 'custom_field_mapping', $new_values ); } // version is less than 1.13 if ( version_compare( '1.30', $current_version, '>' ) ) { /* * Add metadata values to custom field mapping rules */ $new_values = array(); foreach ( MLACore::mla_get_option( 'custom_field_mapping' ) as $key => $value ) { $value['meta_name'] = isset( $value['meta_name'] ) ? $value['meta_name'] : ''; $value['meta_single'] = ( isset( $value['meta_single'] ) && $value['meta_single'] ) ? true : false; $value['meta_export'] = ( isset( $value['meta_export'] ) && $value['meta_export'] ) ? true : false; $new_values[ $key ] = $value; } MLACore::mla_update_option( 'custom_field_mapping', $new_values ); } // version is less than 1.30 if ( version_compare( '1.40', $current_version, '>' ) ) { /* * Add metadata values to custom field mapping rules */ $new_values = array(); foreach ( MLACore::mla_get_option( 'custom_field_mapping' ) as $key => $value ) { $value['no_null'] = ( isset( $value['no_null'] ) && $value['no_null'] ) ? true : false; if ( isset( $value['meta_single'] ) && $value['meta_single'] ) { $value['option'] = 'single'; } elseif ( isset( $value['meta_export'] ) && $value['meta_export'] ) { $value['option'] = 'export'; } else { $value['option'] = 'text'; } unset( $value['meta_single'] ); unset( $value['meta_export'] ); $new_values[ $key ] = $value; } MLACore::mla_update_option( 'custom_field_mapping', $new_values ); } // version is less than 1.40 if ( version_compare( '1.60', $current_version, '>' ) ) { /* * Add delimiters values to taxonomy mapping rules */ $option_value = MLACore::mla_get_option( 'iptc_exif_mapping' ); $new_values = array(); foreach ( $option_value['taxonomy'] as $key => $value ) { $value['delimiters'] = isset( $value['delimiters'] ) ? $value['delimiters'] : ''; $new_values[ $key ] = $value; } $option_value['taxonomy'] = $new_values; MLACore::mla_update_option( 'iptc_exif_mapping', $option_value ); } // version is less than 1.60 if ( version_compare( '1.72', $current_version, '>' ) ) { /* * Strip default descriptions from the options table */ MLAMime::mla_update_upload_mime(); } // version is less than 1.72 if ( version_compare( '2.13', $current_version, '>' ) ) { /* * Add format, option and no_null to IPTC/EXIF custom mapping rules */ $option_value = MLACore::mla_get_option( 'iptc_exif_mapping' ); if ( !empty( $option_value['custom'] ) ) { $new_values = array(); foreach ( $option_value['custom'] as $key => $value ) { $value['format'] = isset( $value['format'] ) ? $value['format'] : 'native'; $value['option'] = isset( $value['option'] ) ? $value['option'] : 'text'; $value['no_null'] = isset( $value['no_null'] ) ? $value['no_null'] : false; $new_values[ $key ] = $value; } $option_value['custom'] = $new_values; MLACore::mla_update_option( 'iptc_exif_mapping', $option_value ); } } // version is less than 2.13 MLACore::mla_update_option( MLACoreOptions::MLA_VERSION_OPTION, MLACore::CURRENT_MLA_VERSION ); } /** * Perform one-time actions on plugin activation * * @since 0.40 * * @return void */ public static function mla_activation_hook( ) { /* * Disable the uninstall file while the plugin is active */ if ( file_exists( MLA_PLUGIN_PATH . 'uninstall.php' ) ) { @rename ( MLA_PLUGIN_PATH . 'uninstall.php' , MLA_PLUGIN_PATH . 'mla-uninstall.php' ); } } /** * Perform one-time actions on plugin deactivation * * @since 0.40 * * @return void */ public static function mla_deactivation_hook( ) { $delete_option_settings = 'checked' === MLACore::mla_get_option( MLACoreOptions::MLA_DELETE_OPTION_SETTINGS ); $delete_option_backups = 'checked' === MLACore::mla_get_option( MLACoreOptions::MLA_DELETE_OPTION_BACKUPS ); /* * We only need the uninstall file if one or both options are true, * otherwise disable it to prevent a false "Delete files and data" warning */ if ( $delete_option_backups || $delete_option_settings ) { if ( file_exists( MLA_PLUGIN_PATH . 'mla-uninstall.php' ) ) { @rename ( MLA_PLUGIN_PATH . 'mla-uninstall.php' , MLA_PLUGIN_PATH . 'uninstall.php' ); } } else { if ( file_exists( MLA_PLUGIN_PATH . 'uninstall.php' ) ) { @rename ( MLA_PLUGIN_PATH . 'uninstall.php' , MLA_PLUGIN_PATH . 'mla-uninstall.php' ); } } } /** * Debug logging for "You do not have sufficient permissions to access this page." * * @since 1.40 * * @return void * / public static function mla_admin_page_access_denied_action() { global $pagenow; global $menu; global $submenu; global $_wp_menu_nopriv; global $_wp_submenu_nopriv; global $plugin_page; global $_registered_pages; error_log( 'DEBUG: mla_admin_page_access_denied_action xdebug_get_function_stack = ' . var_export( xdebug_get_function_stack(), true), 0 ); error_log( 'DEBUG: mla_admin_page_access_denied_action $_SERVER[REQUEST_URI] = ' . var_export( $_SERVER['REQUEST_URI'], true), 0 ); error_log( 'DEBUG: mla_admin_page_access_denied_action $_REQUEST = ' . var_export( $_REQUEST, true), 0 ); error_log( 'DEBUG: mla_admin_page_access_denied_action $pagenow = ' . var_export( $pagenow, true), 0 ); error_log( 'DEBUG: mla_admin_page_access_denied_action $parent = ' . var_export( get_admin_page_parent(), true), 0 ); error_log( 'DEBUG: mla_admin_page_access_denied_action $menu = ' . var_export( $menu, true), 0 ); error_log( 'DEBUG: mla_admin_page_access_denied_action $submenu = ' . var_export( $submenu, true), 0 ); error_log( 'DEBUG: mla_admin_page_access_denied_action $_wp_menu_nopriv = ' . var_export( $_wp_menu_nopriv, true), 0 ); error_log( 'DEBUG: mla_admin_page_access_denied_action $_wp_submenu_nopriv = ' . var_export( $_wp_submenu_nopriv, true), 0 ); error_log( 'DEBUG: mla_admin_page_access_denied_action $plugin_page = ' . var_export( $plugin_page, true), 0 ); error_log( 'DEBUG: mla_admin_page_access_denied_action $_registered_pages = ' . var_export( $_registered_pages, true), 0 ); } // */ /** * Load the plugin's Ajax handler * * @since 1.40 * * @return void */ public static function mla_admin_init_action() { add_action( 'wp_ajax_' . self::JAVASCRIPT_INLINE_EDIT_VIEW_SLUG, 'MLASettings_View::mla_inline_edit_view_action' ); add_action( 'wp_ajax_' . self::JAVASCRIPT_INLINE_EDIT_UPLOAD_SLUG, 'MLASettings_Upload::mla_inline_edit_upload_action' ); add_action( 'wp_ajax_' . self::JAVASCRIPT_INLINE_EDIT_CUSTOM_SLUG, 'MLASettings_CustomFields::mla_inline_edit_custom_action' ); add_action( 'wp_ajax_' . self::JAVASCRIPT_INLINE_MAPPING_CUSTOM_SLUG, 'MLASettings_CustomFields::mla_inline_mapping_custom_action' ); add_action( 'wp_ajax_' . self::JAVASCRIPT_INLINE_EDIT_IPTC_EXIF_SLUG, 'MLASettings_IPTCEXIF::mla_inline_edit_iptc_exif_action' ); add_action( 'wp_ajax_' . self::JAVASCRIPT_INLINE_MAPPING_IPTC_EXIF_SLUG, 'MLASettings_IPTCEXIF::mla_inline_mapping_iptc_exif_action' ); } /** * Load the plugin's Style Sheet and Javascript files * * @since 1.40 * * @param string Name of the page being loaded * * @return void */ public static function mla_admin_enqueue_scripts_action( $page_hook ) { global $wpdb, $wp_locale; /* * Without a tab value, there's nothing to do */ if ( ( self::$current_page_hook != $page_hook ) || empty( $_REQUEST['mla_tab'] ) ) { return; } if ( $wp_locale->is_rtl() ) { wp_register_style( MLACore::STYLESHEET_SLUG, MLA_PLUGIN_URL . 'css/mla-style-rtl.css', false, MLACore::CURRENT_MLA_VERSION ); } else { wp_register_style( MLACore::STYLESHEET_SLUG, MLA_PLUGIN_URL . 'css/mla-style.css', false, MLACore::CURRENT_MLA_VERSION ); } wp_enqueue_style( MLACore::STYLESHEET_SLUG ); } /** * Add settings page in the "Settings" section, * add screen options and help tabs, * add settings link in the Plugins section entry for MLA. * * @since 0.1 * * @return void */ public static function mla_admin_menu_action( ) { /* * We need a tab-specific page ID to manage the screen options on the Views and Uploads tabs. * Use the URL suffix, if present. If the URL doesn't have a tab suffix, use '-general'. * This hack is required to pass the WordPress "referer" validation. */ if ( isset( $_REQUEST['page'] ) && is_string( $_REQUEST['page'] ) && ( 'mla-settings-menu-' == substr( $_REQUEST['page'], 0, 18 ) ) ) { $tab = substr( $_REQUEST['page'], 18 ); } else { $tab = 'general'; } $tab = self::_get_options_tablist( $tab ) ? '-' . $tab : '-general'; self::$current_page_hook = add_submenu_page( 'options-general.php', __( 'Media Library Assistant', 'media-library-assistant' ) . ' ' . __( 'Settings', 'media-library-assistant' ), __( 'Media Library Assistant', 'media-library-assistant' ), 'manage_options', MLACoreOptions::MLA_SETTINGS_SLUG . $tab, 'MLASettings::mla_render_settings_page' ); add_action( 'load-' . self::$current_page_hook, 'MLASettings::mla_add_menu_options_action' ); add_action( 'load-' . self::$current_page_hook, 'MLASettings::mla_add_help_tab_action' ); add_filter( 'plugin_action_links', 'MLASettings::mla_add_plugin_settings_link_filter', 10, 2 ); } /** * Add the "XX Entries per page" filter to the Screen Options tab * * @since 1.40 * * @return void */ public static function mla_add_menu_options_action( ) { if ( isset( $_REQUEST['mla_tab'] ) ) { if ( 'view' == $_REQUEST['mla_tab'] ) { $option = 'per_page'; $args = array( 'label' => __( 'Views per page', 'media-library-assistant' ), 'default' => 10, 'option' => 'mla_views_per_page' ); add_screen_option( $option, $args ); } // view elseif ( isset( $_REQUEST['mla-optional-uploads-display'] ) || isset( $_REQUEST['mla-optional-uploads-search'] ) ) { $option = 'per_page'; $args = array( 'label' => __( 'Types per page', 'media-library-assistant' ), 'default' => 10, 'option' => 'mla_types_per_page' ); add_screen_option( $option, $args ); } // optional upload elseif ( 'upload' == $_REQUEST['mla_tab'] ) { $option = 'per_page'; $args = array( 'label' => __( 'Upload types per page', 'media-library-assistant' ), 'default' => 10, 'option' => 'mla_uploads_per_page' ); add_screen_option( $option, $args ); } // upload elseif ( 'shortcodes' == $_REQUEST['mla_tab'] ) { $option = 'per_page'; $args = array( 'label' => __( 'Shortcode templates per page', 'media-library-assistant' ), 'default' => 10, 'option' => 'mla_shortcode_templates_per_page' ); add_screen_option( $option, $args ); } // shortcodes elseif ( 'custom_field' == $_REQUEST['mla_tab'] ) { $option = 'per_page'; $args = array( 'label' => __( 'Rules per page', 'media-library-assistant' ), 'default' => 10, 'option' => 'mla_custom_field_rules_per_page' ); add_screen_option( $option, $args ); } // custom_field elseif ( 'iptc_exif' == $_REQUEST['mla_tab'] ) { $option = 'per_page'; $args = array( 'label' => __( 'Rules per page', 'media-library-assistant' ), 'default' => 10, 'option' => 'mla_iptc_exif_rules_per_page' ); add_screen_option( $option, $args ); } // iptc_exif elseif ( 'documentation' == $_REQUEST['mla_tab'] ) { if ( isset( $_REQUEST['mla-example-display'] ) || isset( $_REQUEST['mla-example-search'] ) ) { $option = 'per_page'; $args = array( 'label' => __( 'Plugins per page', 'media-library-assistant' ), 'default' => 10, 'option' => 'mla_example_plugins_per_page' ); add_screen_option( $option, $args ); } } // documentation } // isset mla_tab } /** * Add contextual help tabs to all the MLA pages * * @since 1.40 * * @return void */ public static function mla_add_help_tab_action( ) { $screen = get_current_screen(); // Do we have options/help information for this tab? $screen_suffix = substr( $screen->id, strlen( 'settings_page_' . MLACoreOptions::MLA_SETTINGS_SLUG ) ) ; if ( ! in_array( $screen_suffix, array( '-view', '-upload', '-shortcodes', '-custom_field', '-iptc_exif', '-documentation' ) ) ) { return; } $file_suffix = self::$current_page_hook; /* * Override the screen suffix if we are going to display something other than the attachment table */ if ( isset( $_REQUEST['mla-optional-uploads-display'] ) || isset( $_REQUEST['mla-optional-uploads-search'] ) ) { $file_suffix .= '-optional'; } elseif ( isset( $_REQUEST['mla-example-display'] ) || isset( $_REQUEST['mla-example-search'] ) ) { $file_suffix = str_replace( '-documentation', '-example', $file_suffix ); } elseif ( isset( $_REQUEST['mla_admin_action'] ) ) { switch ( $_REQUEST['mla_admin_action'] ) { case MLACore::MLA_ADMIN_SINGLE_EDIT_DISPLAY: $file_suffix .= '-edit'; break; } // switch } // isset( $_REQUEST['mla_admin_action'] ) $template_array = MLACore::mla_load_template( 'help-for-' . $file_suffix . '.tpl' ); if ( empty( $template_array ) ) { return; } if ( !empty( $template_array['sidebar'] ) ) { $page_values = array( 'settingsURL' => admin_url('options-general.php') ); $content = MLAData::mla_parse_template( $template_array['sidebar'], $page_values ); $screen->set_help_sidebar( $content ); unset( $template_array['sidebar'] ); } /* * Provide explicit control over tab order */ $tab_array = array(); foreach ( $template_array as $id => $content ) { $match_count = preg_match( '#\