add_filter( 'plugin_icon', 'fs_custom_optin_icon__premium_only' ); } // ===== Activate features based on settings ===== // Get all WP Enhancements options, default to empty array in case it's not been created yet $options = get_option( ASENHA_SLUG_U, array() ); // ================================================================= // CONTENT MANAGEMENT // ================================================================= // Instantiate object for Content Management features $content_management = new ASENHA\Classes\Content_Management(); // Content Duplication if ( array_key_exists( 'enable_duplication', $options ) && $options['enable_duplication'] ) { add_action( 'admin_action_asenha_enable_duplication', [ $content_management, 'asenha_enable_duplication' ] ); add_filter( 'page_row_actions', [ $content_management, 'add_duplication_action_link' ], 10, 2 ); add_filter( 'post_row_actions', [ $content_management, 'add_duplication_action_link' ], 10, 2 ); } // Content Order if ( array_key_exists( 'content_order', $options ) && $options['content_order'] ) { if ( array_key_exists( 'content_order_for', $options ) && !empty($options['content_order_for']) ) { add_action( 'admin_menu', [ $content_management, 'add_content_order_submenu' ] ); add_action( 'wp_ajax_save_custom_order', [ $content_management, 'save_custom_content_order' ] ); add_filter( 'pre_get_posts', [ $content_management, 'orderby_menu_order' ] ); add_filter( 'save_post', [ $content_management, 'set_menu_order_for_new_posts' ], 10, 3 ); } } // Media Replacement if ( array_key_exists( 'enable_media_replacement', $options ) && $options['enable_media_replacement'] ) { add_filter( 'media_row_actions', [ $content_management, 'modify_media_list_table_edit_link' ], 10, 2 ); add_filter( 'attachment_fields_to_edit', [ $content_management, 'add_media_replacement_button' ], 10, 2 ); add_action( 'edit_attachment', [ $content_management, 'replace_media' ] ); add_filter( 'post_updated_messages', [ $content_management, 'attachment_updated_custom_message' ] ); // Bust browser cache of old/replaced images add_filter( 'wp_calculate_image_srcset', [ $content_management, 'append_cache_busting_param_to_image_srcset' ], 10, 5 ); add_filter( 'wp_get_attachment_image_src', [ $content_management, 'append_cache_busting_param_to_attachment_image_src' ], 10, 2 ); add_filter( 'wp_prepare_attachment_for_js', [ $content_management, 'append_cache_busting_param_to_attachment_for_js' ], 10, 2 ); } // Enable SVG Upload if ( array_key_exists( 'enable_svg_upload', $options ) && $options['enable_svg_upload'] && array_key_exists( 'enable_svg_upload_for', $options ) && isset( $options['enable_svg_upload_for'] ) ) { global $roles_svg_upload_enabled ; $enable_svg_upload = $options['enable_svg_upload']; $for_roles = $options['enable_svg_upload_for']; // User has role(s). Do further checks. if ( isset( $for_roles ) && count( $for_roles ) > 0 ) { // Assemble single-dimensional array of roles for which SVG upload would be enabled $roles_svg_upload_enabled = array(); foreach ( $for_roles as $role_slug => $svg_upload_enabled ) { if ( $svg_upload_enabled ) { $roles_svg_upload_enabled[] = $role_slug; } } } add_filter( 'upload_mimes', [ $content_management, 'add_svg_mime' ] ); add_filter( 'wp_check_filetype_and_ext', [ $content_management, 'confirm_file_type_is_svg' ], 10, 4 ); add_filter( 'wp_handle_upload_prefilter', [ $content_management, 'sanitize_and_maybe_allow_svg_upload' ] ); add_filter( 'wp_generate_attachment_metadata', [ $content_management, 'generate_svg_metadata' ], 10, 3 ); add_action( 'wp_ajax_svg_get_attachment_url', [ $content_management, 'get_svg_attachment_url' ] ); add_filter( 'wp_prepare_attachment_for_js', [ $content_management, 'get_svg_url_in_media_library' ] ); } // Enable External Permalinks if ( array_key_exists( 'enable_external_permalinks', $options ) && $options['enable_external_permalinks'] ) { if ( array_key_exists( 'enable_external_permalinks_for', $options ) && !empty($options['enable_external_permalinks_for']) ) { add_action( 'add_meta_boxes', [ $content_management, 'add_external_permalink_meta_box' ], 10, 2 ); add_action( 'save_post', [ $content_management, 'save_external_permalink' ] ); // Filter the permalink for use by get_permalink() add_filter( 'page_link', [ $content_management, 'use_external_permalink_for_pages' ], 20, 2 ); add_filter( 'post_link', [ $content_management, 'use_external_permalink_for_posts' ], 20, 2 ); add_filter( 'post_type_link', [ $content_management, 'use_external_permalink_for_posts' ], 20, 2 ); // Enable redirection to external permalink when page/post is opened directly via it's WP permalink add_action( 'wp', [ $content_management, 'redirect_to_external_permalink' ] ); } } // Open All External Links in New Tab if ( array_key_exists( 'external_links_new_tab', $options ) && $options['external_links_new_tab'] ) { add_filter( 'the_content', [ $content_management, 'add_target_and_rel_atts_to_content_links' ] ); } // Allow Custom Menu Links to Open in New Tab if ( array_key_exists( 'custom_nav_menu_items_new_tab', $options ) && $options['custom_nav_menu_items_new_tab'] ) { add_filter( 'wp_nav_menu_item_custom_fields', [ $content_management, 'add_custom_nav_menu_open_in_new_tab_field' ], 10, 4 ); add_action( 'wp_update_nav_menu_item', [ $content_management, 'save_custom_nav_menu_open_in_new_tab_status' ], 10, 3 ); add_action( 'nav_menu_link_attributes', [ $content_management, 'add_attributes_to_custom_nav_menu_item' ], 10, 3 ); } // Enable Auto-Publishing of Posts with Missed Schedules if ( array_key_exists( 'enable_missed_schedule_posts_auto_publish', $options ) && $options['enable_missed_schedule_posts_auto_publish'] ) { add_action( 'wp_head', [ $content_management, 'publish_missed_schedule_posts' ] ); add_action( 'admin_head', [ $content_management, 'publish_missed_schedule_posts' ] ); } // ================================================================= // ADMIN INTERFACE // ================================================================= // Instantiate object for Admin Interface features $admin_interface = new ASENHA\Classes\Admin_Interface(); // Hide or Modify Elements / Clean Up Admin Bar if ( array_key_exists( 'hide_modify_elements', $options ) && $options['hide_modify_elements'] ) { // Priority 5 to execute earlier than the normal 10. This is for removing default items. add_filter( 'admin_bar_menu', [ $admin_interface, 'modify_admin_bar_menu' ], 5 ); if ( array_key_exists( 'hide_help_drawer', $options ) && $options['hide_help_drawer'] ) { add_action( 'admin_head', [ $admin_interface, 'hide_help_drawer' ] ); } } // Hide Admin Notices if ( array_key_exists( 'hide_admin_notices', $options ) && $options['hide_admin_notices'] ) { add_action( 'admin_notices', [ $admin_interface, 'admin_notices_wrapper' ], 9 ); // add_action( 'all_admin_notices', [ $admin_interface, 'admin_notices_wrapper' ] ); add_action( 'admin_bar_menu', [ $admin_interface, 'admin_notices_menu' ] ); add_action( 'admin_enqueue_scripts', [ $admin_interface, 'admin_notices_menu_inline_css' ] ); // wp-admin } // Disable Dashboard Widgets if ( array_key_exists( 'disable_dashboard_widgets', $options ) && $options['disable_dashboard_widgets'] ) { add_action( 'wp_dashboard_setup', [ $admin_interface, 'disable_dashboard_widgets' ], 99 ); } // Hide Admin Bar // On the frontend if ( array_key_exists( 'hide_admin_bar', $options ) && $options['hide_admin_bar'] && array_key_exists( 'hide_admin_bar_for', $options ) && isset( $options['hide_admin_bar_for'] ) ) { add_filter( 'show_admin_bar', [ $admin_interface, 'hide_admin_bar_for_roles_on_frontend' ] ); } // Wider Admin Menu if ( array_key_exists( 'wider_admin_menu', $options ) && $options['wider_admin_menu'] ) { add_action( 'admin_head', [ $admin_interface, 'set_custom_menu_width' ], 99 ); } // Admin Menu Organizer if ( array_key_exists( 'customize_admin_menu', $options ) && $options['customize_admin_menu'] ) { // add_action( 'wp_ajax_save_custom_menu_order', [ $admin_interface, 'save_custom_menu_order' ] ); // add_action( 'wp_ajax_save_hidden_menu_items', [ $admin_interface, 'save_hidden_menu_items' ] ); if ( array_key_exists( 'custom_menu_order', $options ) ) { add_filter( 'custom_menu_order', '__return_true' ); add_filter( 'menu_order', [ $admin_interface, 'render_custom_menu_order' ], PHP_INT_MAX ); } if ( array_key_exists( 'custom_menu_titles', $options ) ) { add_action( 'admin_menu', [ $admin_interface, 'apply_custom_menu_item_titles' ], 999995 ); } if ( array_key_exists( 'custom_menu_hidden', $options ) || array_key_exists( 'custom_menu_always_hidden', $options ) ) { add_action( 'admin_menu', [ $admin_interface, 'hide_menu_items' ], 999996 ); add_action( 'admin_menu', [ $admin_interface, 'add_hidden_menu_toggle' ], 999997 ); add_action( 'admin_enqueue_scripts', [ $admin_interface, 'enqueue_toggle_hidden_menu_script' ] ); } } // Enhance List Tables if ( array_key_exists( 'enhance_list_tables', $options ) && $options['enhance_list_tables'] ) { // Show Featured Image Column if ( array_key_exists( 'show_featured_image_column', $options ) && $options['show_featured_image_column'] ) { add_action( 'admin_init', [ $admin_interface, 'show_featured_image_column' ] ); } // Show Excerpt Column if ( array_key_exists( 'show_excerpt_column', $options ) && $options['show_excerpt_column'] ) { add_action( 'admin_init', [ $admin_interface, 'show_excerpt_column' ] ); } // Show ID Column if ( array_key_exists( 'show_id_column', $options ) && $options['show_id_column'] ) { add_action( 'admin_init', [ $admin_interface, 'show_id_column' ] ); } // Show ID in Action Row if ( array_key_exists( 'show_id_in_action_row', $options ) && $options['show_id_in_action_row'] ) { add_action( 'admin_init', [ $admin_interface, 'show_id_in_action_row' ] ); } // Show Custom Taxonomy Filters if ( array_key_exists( 'show_custom_taxonomy_filters', $options ) && $options['show_custom_taxonomy_filters'] ) { add_action( 'restrict_manage_posts', [ $admin_interface, 'show_custom_taxonomy_filters' ] ); } // Hide Comments Column if ( array_key_exists( 'hide_comments_column', $options ) && $options['hide_comments_column'] ) { add_action( 'admin_init', [ $admin_interface, 'hide_comments_column' ] ); } // Hide Post Tags Column if ( array_key_exists( 'hide_post_tags_column', $options ) && $options['hide_post_tags_column'] ) { add_action( 'admin_init', [ $admin_interface, 'hide_post_tags_column' ] ); } } // ================================================================= // LOG IN | LOG OUT // ================================================================= // Instantiate object for Log In Log Out features $login_logout = new ASENHA\Classes\Login_Logout(); // Change Login URL if ( array_key_exists( 'change_login_url', $options ) && $options['change_login_url'] ) { if ( array_key_exists( 'custom_login_slug', $options ) && !empty($options['custom_login_slug']) ) { add_action( 'init', [ $login_logout, 'redirect_on_custom_login_url' ] ); add_filter( 'lostpassword_url', [ $login_logout, 'customize_lost_password_url' ] ); add_action( 'wp_loaded', [ $login_logout, 'redirect_on_default_login_urls' ] ); add_action( 'wp_login_failed', [ $login_logout, 'redirect_to_custom_login_url_on_login_fail' ] ); add_action( 'wp_logout', [ $login_logout, 'redirect_to_custom_login_url_on_logout_success' ] ); } } // Use Site Identity on the Login Page if ( array_key_exists( 'site_identity_on_login', $options ) && $options['site_identity_on_login'] ) { add_action( 'login_head', [ $login_logout, 'use_site_icon_on_login' ] ); add_filter( 'login_headerurl', [ $login_logout, 'use_site_url_on_login' ] ); } // Enable Login Logout Menu if ( array_key_exists( 'enable_login_logout_menu', $options ) && $options['enable_login_logout_menu'] ) { add_action( 'admin_head-nav-menus.php', [ $login_logout, 'add_login_logout_metabox' ] ); add_filter( 'wp_setup_nav_menu_item', [ $login_logout, 'set_login_logout_menu_item_dynamic_url' ] ); add_filter( 'wp_nav_menu_objects', [ $login_logout, 'maybe_remove_login_or_logout_menu_item' ] ); } // Enable Last Login Column if ( array_key_exists( 'enable_last_login_column', $options ) && $options['enable_last_login_column'] ) { add_action( 'wp_login', [ $login_logout, 'log_login_datetime' ] ); add_filter( 'manage_users_columns', [ $login_logout, 'add_last_login_column' ] ); add_filter( 'manage_users_custom_column', [ $login_logout, 'show_last_login_info' ], 10, 3 ); add_action( 'admin_print_styles-users.php', [ $login_logout, 'add_column_style' ] ); } // Redirect After Login if ( array_key_exists( 'redirect_after_login', $options ) && $options['redirect_after_login'] ) { if ( array_key_exists( 'redirect_after_login_to_slug', $options ) && !empty($options['redirect_after_login_to_slug']) ) { if ( array_key_exists( 'redirect_after_login_for', $options ) && !empty($options['redirect_after_login_for']) ) { add_filter( 'wp_login', [ $login_logout, 'redirect_for_roles_after_login' ], 5, 2 ); } } } // Redirect After Logout if ( array_key_exists( 'redirect_after_logout', $options ) && $options['redirect_after_logout'] ) { if ( array_key_exists( 'redirect_after_logout_to_slug', $options ) && !empty($options['redirect_after_logout_to_slug']) ) { if ( array_key_exists( 'redirect_after_logout_for', $options ) && !empty($options['redirect_after_logout_for']) ) { add_action( 'wp_logout', [ $login_logout, 'redirect_after_logout' ], 5, 1 ); // load earlier than Change Login URL add_action } } } // ================================================================= // CUSTOM CODE // ================================================================= // Instantiate object for Custom Code features $custom_code = new ASENHA\Classes\Custom_Code(); // Enable Custom Admin / Frontend CSS if ( array_key_exists( 'enable_custom_admin_css', $options ) && $options['enable_custom_admin_css'] ) { add_filter( 'admin_enqueue_scripts', [ $custom_code, 'custom_admin_css' ] ); } if ( array_key_exists( 'enable_custom_frontend_css', $options ) && $options['enable_custom_frontend_css'] ) { add_filter( 'wp_head', [ $custom_code, 'custom_frontend_css' ] ); } // Custom Body Class if ( array_key_exists( 'enable_custom_body_class', $options ) && $options['enable_custom_body_class'] ) { if ( array_key_exists( 'enable_custom_body_class_for', $options ) && !empty($options['enable_custom_body_class_for']) ) { add_action( 'add_meta_boxes', [ $custom_code, 'add_custom_body_class_meta_box' ], 10, 2 ); add_action( 'save_post', [ $custom_code, 'save_custom_body_class' ], 99 ); add_filter( 'body_class', [ $custom_code, 'append_custom_body_class' ], 99 ); } } // Manage ads.txt and app-ads.txt if ( array_key_exists( 'manage_ads_appads_txt', $options ) && $options['manage_ads_appads_txt'] ) { add_action( 'init', [ $custom_code, 'show_ads_appads_txt_content' ] ); } // Manage robots.txt if ( array_key_exists( 'manage_robots_txt', $options ) && $options['manage_robots_txt'] ) { add_filter( 'robots_txt', [ $custom_code, 'maybe_show_custom_robots_txt_content' ], 10, 2 ); } // Insert
, and