Plugin Directory

source: comment-controller/trunk/class-comment-controller.php

Last change on this file was 3453201, checked in by digitalmeactivecampaign, 8 weeks ago

Version 1.1.5 - Update author and test with WordPress 6.9

File size: 5.8 KB
Line 
1<?php
2/**
3 * Plugin Name:     Comment Controller
4 * Plugin URI:      https://wordpress.org/plugins/comment-controller/
5 * Description:     Selectively disable comments on a per-user basis
6 * Author:          DigitalME
7 * Author URI:      https://digitalme.cc
8 * Version:         1.1.5
9 * Text Domain:     comment-controller
10 * Domain Path:     languages
11 * License:         GPLv2 or later
12 * License URI:     http://www.gnu.org/licenses/gpl-2.0.html
13 *
14 * @package         CommentController
15 * @author          DigitalME <support@digitalme.cc>
16 */
17
18// Exit if accessed directly.
19if ( ! defined( 'ABSPATH' ) ) {
20        exit;
21}
22
23
24if ( ! class_exists( 'Comment_Controller' ) ) {
25
26
27        /**
28         * Main Comment_Controller class
29         *
30         * @access      public
31         * @since       1.0.0
32         */
33        final class Comment_Controller {
34
35
36                /**
37                 * The one true Comment_Controller
38                 *
39                 * @access      private
40                 * @since       1.0.0
41                 * @var         Comment_Controller $instance The one true Comment_Controller
42                 */
43                private static $instance;
44
45
46                /**
47                 * The settings object
48                 *
49                 * @access      public
50                 * @since       1.1.0
51                 * @var         object $settings The settings object
52                 */
53                public $settings;
54
55
56                /**
57                 * Get active instance
58                 *
59                 * @access      public
60                 * @since       1.0.0
61                 * @static
62                 * @return      self::$instance The one true Comment_Controller
63                 */
64                public static function instance() {
65                        if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Comment_Controller ) ) {
66                                self::$instance = new Comment_Controller();
67                                self::$instance->setup_constants();
68                                self::$instance->hooks();
69                                self::$instance->includes();
70                        }
71
72                        return self::$instance;
73                }
74
75
76                /**
77                 * Throw error on object clone
78                 *
79                 * The whole idea of the singleton design pattern is that there is
80                 * a single object. Therefore, we don't want the object to be cloned.
81                 *
82                 * @access      protected
83                 * @since       1.1.0
84                 * @return      void
85                 */
86                public function __clone() {
87                        _doing_it_wrong( __FUNCTION__, esc_attr__( 'Cheatin&#8217; huh?', 'comment-controller' ), '1.0.0' );
88                }
89
90
91                /**
92                 * Disable unserializing of the class
93                 *
94                 * @access      protected
95                 * @since       1.1.0
96                 * @return      void
97                 */
98                public function __wakeup() {
99                        _doing_it_wrong( __FUNCTION__, esc_attr__( 'Cheatin&#8217; huh?', 'comment-controller' ), '1.0.0' );
100                }
101
102
103                /**
104                 * Setup plugin constants
105                 *
106                 * @access      private
107                 * @since       1.1.0
108                 * @return      void
109                 */
110                private function setup_constants() {
111                        // Plugin version.
112                        if ( ! defined( 'COMMENT_CONTROLLER_VER' ) ) {
113                                define( 'COMMENT_CONTROLLER_VER', '1.1.4' );
114                        }
115
116                        // Plugin path.
117                        if ( ! defined( 'COMMENT_CONTROLLER_DIR' ) ) {
118                                define( 'COMMENT_CONTROLLER_DIR', plugin_dir_path( __FILE__ ) );
119                        }
120
121                        // Plugin URL.
122                        if ( ! defined( 'COMMENT_CONTROLLER_URL' ) ) {
123                                define( 'COMMENT_CONTROLLER_URL', plugin_dir_url( __FILE__ ) );
124                        }
125                }
126
127
128                /**
129                 * Run plugin base hooks
130                 *
131                 * @access      private
132                 * @since       1.1.0
133                 * @return      void
134                 */
135                private function hooks() {
136                        add_action( 'plugins_loaded', array( self::$instance, 'load_textdomain' ) );
137                }
138
139
140                /**
141                 * Include required files
142                 *
143                 * @access      private
144                 * @since       1.0.0
145                 * @return      void
146                 */
147                private function includes() {
148                        global $comment_controller_options;
149
150                        // Load settings handler if necessary.
151                        if ( ! class_exists( 'Simple_Settings' ) ) {
152                                require_once COMMENT_CONTROLLER_DIR . 'vendor/widgitlabs/simple-settings/class-simple-settings.php';
153                        }
154
155                        require_once COMMENT_CONTROLLER_DIR . 'includes/admin/settings/register-settings.php';
156
157                        self::$instance->settings   = new Simple_Settings( 'comment_controller', 'settings' );
158                        $comment_controller_options = self::$instance->settings->get_settings();
159
160                        require_once COMMENT_CONTROLLER_DIR . 'includes/misc-functions.php';
161                        require_once COMMENT_CONTROLLER_DIR . 'includes/profile.php';
162                }
163
164
165                /**
166                 * Internationalization
167                 *
168                 * @access      public
169                 * @since       1.0.0
170                 * @return      void
171                 */
172                public function load_textdomain() {
173                        // Set filter for language directory.
174                        $lang_dir = dirname( plugin_basename( __FILE__ ) ) . '/languages/';
175                        $lang_dir = apply_filters( 'comment_controller_languages_directory', $lang_dir );
176
177                        // Traditional WordPress plugin locale filter.
178                        $locale = apply_filters( 'plugin_locale', get_locale(), '' );
179                        $mofile = sprintf( '%1$s-%2$s.mo', 'comment-controller', $locale );
180
181                        // Setup paths to current locale file.
182                        $mofile_local  = $lang_dir . $mofile;
183                        $mofile_global = WP_LANG_DIR . '/comment-controller/' . $mofile;
184                        $mofile_core   = WP_LANG_DIR . '/plugins/comment-controller/' . $mofile;
185
186                        if ( file_exists( $mofile_global ) ) {
187                                // Look in global /wp-content/languages/comment-controller/ folder.
188                                load_textdomain( 'comment-controller', $mofile_global );
189                        } elseif ( file_exists( $mofile_local ) ) {
190                                // Look in local /wp-content/plugins/comment-controller/languages/ folder.
191                                load_textdomain( 'comment-controller', $mofile_local );
192                        } elseif ( file_exists( $mofile_core ) ) {
193                                // Look in core /wp-content/languages/plugins/comment-controller/ folder.
194                                load_textdomain( 'comment-controller', $mofile_core );
195                        } else {
196                                // Load the default language files.
197                                load_plugin_textdomain( 'comment-controller', false, $lang_dir );
198                        }
199                }
200        }
201}
202
203
204/**
205 * The main function responsible for returning the one true Comment_Controller
206 * instance to functions everywhere.
207 *
208 * Use this function like you would a global variable, except without
209 * needing to declare the global.
210 *
211 * Example: <?php $comment_controller = Comment_Controller(); ?>
212 *
213 * @since       1.1.0
214 * @return      Comment_Controller The one true Comment_Controller
215 */
216function comment_controller() {
217        return Comment_Controller::instance();
218}
219
220// Get things started.
221Comment_Controller();
Note: See TracBrowser for help on using the repository browser.