admin-site-enhancements
Last commit date
assets
3 years ago
classes
3 years ago
includes
3 years ago
LICENSE.md
3 years ago
README.md
3 years ago
admin-site-enhancements.php
3 years ago
bootstrap.php
3 years ago
bootstrap.php
128 lines
| 1 | <?php |
| 2 | |
| 3 | // We're using the singleton design pattern |
| 4 | // https://code.tutsplus.com/articles/design-patterns-in-wordpress-the-singleton-pattern--wp-31621 |
| 5 | // https://carlalexander.ca/singletons-in-wordpress/ |
| 6 | // https://torquemag.io/2016/11/singletons-wordpress-good-evil/ |
| 7 | |
| 8 | /** |
| 9 | * Main class of the plugin used to add functionalities |
| 10 | * |
| 11 | * @since 1.0.0 |
| 12 | */ |
| 13 | class Admin_Site_Enhancements { |
| 14 | |
| 15 | // Refers to a single instance of this class |
| 16 | private static $instance = null; |
| 17 | |
| 18 | /** |
| 19 | * Creates or returns a single instance of this class |
| 20 | * |
| 21 | * @return Admin_Site_Enhancements a single instance of this class |
| 22 | * @since 1.0.0 |
| 23 | */ |
| 24 | public static function get_instance() { |
| 25 | |
| 26 | if ( null == self::$instance ) { |
| 27 | |
| 28 | self::$instance = new self; |
| 29 | |
| 30 | } |
| 31 | |
| 32 | return self::$instance; |
| 33 | |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Initialize plugin functionalities |
| 38 | */ |
| 39 | private function __construct() { |
| 40 | |
| 41 | // Setup admin menu, admin page, admin scripts, plugin action links, etc. |
| 42 | |
| 43 | // Register admin menu and add the settings page. |
| 44 | add_action( 'admin_menu', 'asenha_register_admin_menu' ); |
| 45 | |
| 46 | // Register plugin settings |
| 47 | add_action( 'admin_init', 'asenha_register_settings' ); |
| 48 | |
| 49 | // Suppress all notices on the plugin's main page. Then add notification for successful settings update. |
| 50 | add_action( 'admin_notices', 'asenha_notices', 5 ); |
| 51 | |
| 52 | // Enqueue admin scripts and styles only on the plugin's main page |
| 53 | add_action( 'admin_enqueue_scripts', 'asenha_admin_scripts' ); |
| 54 | |
| 55 | // Add action links in plugins page |
| 56 | add_filter( 'plugin_action_links_' . ASENHA_SLUG . '/' . ASENHA_SLUG . '.php', 'asenha_plugin_action_links' ); |
| 57 | |
| 58 | // Update footer text |
| 59 | add_filter( 'admin_footer_text', 'asenha_footer_text' ); |
| 60 | |
| 61 | // Selectively enable enhancements based on options value |
| 62 | |
| 63 | // Get all WP Enhancements options, default to empty array in case it's not been created yet |
| 64 | $options = get_option( 'admin_site_enhancements', array() ); |
| 65 | |
| 66 | // Instantiate object for Content Management functionalities |
| 67 | $content_management = new ASENHA\Classes\Content_Management; |
| 68 | |
| 69 | // Instantiate object for Admin Interface functionalities |
| 70 | $admin_interface = new ASENHA\Classes\Admin_Interface; |
| 71 | |
| 72 | // Content Management >> Show Featured Image Column |
| 73 | if ( array_key_exists( 'show_featured_image_column', $options ) && $options['show_featured_image_column'] ) { |
| 74 | add_action( 'admin_init', [ $content_management, 'show_featured_image_column' ] ); |
| 75 | } |
| 76 | |
| 77 | // Content Management >> Show Excerpt Column |
| 78 | if ( array_key_exists( 'show_excerpt_column', $options ) && $options['show_excerpt_column'] ) { |
| 79 | add_action( 'admin_init', [ $content_management, 'show_excerpt_column' ] ); |
| 80 | } |
| 81 | |
| 82 | // Content Management >> Show ID Column |
| 83 | if ( array_key_exists( 'show_id_column', $options ) && $options['show_id_column'] ) { |
| 84 | add_action( 'admin_init', [ $content_management, 'show_id_column' ] ); |
| 85 | } |
| 86 | |
| 87 | // Content Management >> Hide Comments Column |
| 88 | if ( array_key_exists( 'hide_comments_column', $options ) && $options['hide_comments_column'] ) { |
| 89 | add_action( 'admin_init', [ $content_management, 'hide_comments_column' ] ); |
| 90 | } |
| 91 | |
| 92 | // Content Management >> Hide Post Tags Column |
| 93 | if ( array_key_exists( 'hide_post_tags_column', $options ) && $options['hide_post_tags_column'] ) { |
| 94 | add_action( 'admin_init', [ $content_management, 'hide_post_tags_column' ] ); |
| 95 | } |
| 96 | |
| 97 | // Content Management >> Show Custom Taxonomy Filters |
| 98 | if ( array_key_exists( 'show_custom_taxonomy_filters', $options ) && $options['show_custom_taxonomy_filters'] ) { |
| 99 | add_action( 'restrict_manage_posts', [ $content_management, 'show_custom_taxonomy_filters' ] ); |
| 100 | } |
| 101 | |
| 102 | // Content Management >> Enable Page and Post Duplication |
| 103 | if ( array_key_exists( 'enable_duplication', $options ) && $options['enable_duplication'] ) { |
| 104 | add_action( 'admin_action_asenha_enable_duplication', [ $content_management, 'asenha_enable_duplication' ] ); |
| 105 | add_filter( 'page_row_actions', [ $content_management, 'add_duplication_action_link' ], 10, 2 ); |
| 106 | add_filter( 'post_row_actions', [ $content_management, 'add_duplication_action_link' ], 10, 2 ); |
| 107 | } |
| 108 | |
| 109 | // Content Management >> Enable Media Replacement |
| 110 | if ( array_key_exists( 'enable_media_replacement', $options ) && $options['enable_media_replacement'] ) { |
| 111 | add_filter( 'media_row_actions', [ $content_management, 'modify_media_list_table_edit_link' ], 10, 2 ); |
| 112 | add_filter( 'attachment_fields_to_edit', [ $content_management, 'add_media_replacement_button' ] ); |
| 113 | add_action( 'edit_attachment', [ $content_management, 'replace_media' ] ); |
| 114 | add_filter( 'post_updated_messages', [ $content_management, 'attachment_updated_custom_message' ] ); |
| 115 | } |
| 116 | |
| 117 | // Content Management >> Hide Admin Notices |
| 118 | if ( array_key_exists( 'hide_admin_notices', $options ) && $options['hide_admin_notices'] ) { |
| 119 | add_action( 'all_admin_notices', [ $admin_interface, 'admin_notices_wrapper' ] ); |
| 120 | add_action( 'admin_bar_menu', [ $admin_interface, 'admin_notices_menu' ] ); |
| 121 | add_action( 'admin_enqueue_scripts', [ $admin_interface, 'admin_notices_menu_inline_css' ] ); // wp-admin |
| 122 | } |
| 123 | |
| 124 | } |
| 125 | |
| 126 | } |
| 127 | |
| 128 | Admin_Site_Enhancements::get_instance(); |