class-steempress_sp.php 7.38 KB
Newer Older
Martin Lees's avatar
Martin Lees committed
1
2
3
4
5
6
7
8
9
10
11
<?php

/**
 * The file that defines the core plugin class
 *
 * A class definition that includes attributes and functions used across both the
 * public-facing side of the site and the admin area.
 *
 * @link       https://steemit.com/@howo
 * @since      1.0.0
 *
Martin Lees's avatar
Martin Lees committed
12
13
 * @package    Steempress_sp
 * @subpackage Steempress_sp/includes
Martin Lees's avatar
Martin Lees committed
14
15
16
17
18
19
20
21
22
23
24
25
 */

/**
 * The core plugin class.
 *
 * This is used to define internationalization, admin-specific hooks, and
 * public-facing site hooks.
 *
 * Also maintains the unique identifier of this plugin as well as the current
 * version of the plugin.
 *
 * @since      1.0.0
Martin Lees's avatar
Martin Lees committed
26
27
 * @package    Steempress_sp
 * @subpackage Steempress_sp/includes
Martin Lees's avatar
Martin Lees committed
28
 */
Martin Lees's avatar
Martin Lees committed
29
class Steempress_sp {
Martin Lees's avatar
Martin Lees committed
30
31
32
33
34
35
36

	/**
	 * The loader that's responsible for maintaining and registering all hooks that power
	 * the plugin.
	 *
	 * @since    1.0.0
	 * @access   protected
Martin Lees's avatar
Martin Lees committed
37
	 * @var      Steempress_sp_Loader    $loader    Maintains and registers all hooks for the plugin.
Martin Lees's avatar
Martin Lees committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
	 */
	protected $loader;

	/**
	 * The unique identifier of this plugin.
	 *
	 * @since    1.0.0
	 * @access   protected
	 * @var      string    $plugin_name    The string used to uniquely identify this plugin.
	 */
	protected $plugin_name;

	/**
	 * The current version of the plugin.
	 *
	 * @since    1.0.0
	 * @access   protected
	 * @var      string    $version    The current version of the plugin.
	 */
	protected $version;

	/**
	 * Define the core functionality of the plugin.
	 *
	 * Set the plugin name and the plugin version that can be used throughout the plugin.
	 * Load the dependencies, define the locale, and set the hooks for the admin area and
	 * the public-facing side of the site.
	 *
	 * @since    1.0.0
	 */
	public function __construct() {
69
		if ( defined( 'steempress_sp_compte' ) ) {
Martin Lees's avatar
Martin Lees committed
70
			$this->version = steempress_sp_compte;
Martin Lees's avatar
Martin Lees committed
71
72
73
		} else {
			$this->version = '1.0.0';
		}
Martin Lees's avatar
Martin Lees committed
74
		$this->plugin_name = 'steempress_sp';
Martin Lees's avatar
Martin Lees committed
75
76
77
78
79
80
81
82
83
84
85
86
87

		$this->load_dependencies();
		$this->set_locale();
		$this->define_admin_hooks();
		$this->define_public_hooks();

	}

	/**
	 * Load the required dependencies for this plugin.
	 *
	 * Include the following files that make up the plugin:
	 *
Martin Lees's avatar
Martin Lees committed
88
89
90
91
	 * - Steempress_sp_Loader. Orchestrates the hooks of the plugin.
	 * - Steempress_sp_i18n. Defines internationalization functionality.
	 * - Steempress_sp_Admin. Defines all hooks for the admin area.
	 * - Steempress_sp_Public. Defines all hooks for the public side of the site.
Martin Lees's avatar
Martin Lees committed
92
93
94
95
96
97
98
99
100
101
102
103
104
	 *
	 * Create an instance of the loader which will be used to register the hooks
	 * with WordPress.
	 *
	 * @since    1.0.0
	 * @access   private
	 */
	private function load_dependencies() {

		/**
		 * The class responsible for orchestrating the actions and filters of the
		 * core plugin.
		 */
Martin Lees's avatar
Martin Lees committed
105
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-steempress_sp-loader.php';
Martin Lees's avatar
Martin Lees committed
106
107
108
109
110

		/**
		 * The class responsible for defining internationalization functionality
		 * of the plugin.
		 */
Martin Lees's avatar
Martin Lees committed
111
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-steempress_sp-i18n.php';
Martin Lees's avatar
Martin Lees committed
112
113
114
115

		/**
		 * The class responsible for defining all actions that occur in the admin area.
		 */
Martin Lees's avatar
Martin Lees committed
116
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-steempress_sp-admin.php';
Martin Lees's avatar
Martin Lees committed
117
118
119
120
121

		/**
		 * The class responsible for defining all actions that occur in the public-facing
		 * side of the site.
		 */
Martin Lees's avatar
Martin Lees committed
122
		require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-steempress_sp-public.php';
Martin Lees's avatar
Martin Lees committed
123

Martin Lees's avatar
Martin Lees committed
124
		$this->loader = new Steempress_sp_Loader();
Martin Lees's avatar
Martin Lees committed
125
126
127
128
129
130

	}

	/**
	 * Define the locale for this plugin for internationalization.
	 *
Martin Lees's avatar
Martin Lees committed
131
	 * Uses the Steempress_sp_i18n class in order to set the domain and to register the hook
Martin Lees's avatar
Martin Lees committed
132
133
134
135
136
137
138
	 * with WordPress.
	 *
	 * @since    1.0.0
	 * @access   private
	 */
	private function set_locale() {

Martin Lees's avatar
Martin Lees committed
139
		$plugin_i18n = new Steempress_sp_i18n();
Martin Lees's avatar
Martin Lees committed
140
141
142
143
144
145
146
147
148
149
150
151
152
153

		$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );

	}

	/**
	 * Register all of the hooks related to the admin area functionality
	 * of the plugin.
	 *
	 * @since    1.0.0
	 * @access   private
	 */
	private function define_admin_hooks() {

Martin Lees's avatar
Martin Lees committed
154
		$plugin_admin = new Steempress_sp_Admin( $this->get_plugin_name(), $this->get_version() );
Martin Lees's avatar
Martin Lees committed
155
156
157
158
159
160
161
162
163

		$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
		$this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );

        $this->loader->add_action( 'admin_menu', $plugin_admin, 'add_plugin_admin_menu' );

        // Add Settings link to the plugin
        $plugin_basename = plugin_basename( plugin_dir_path( __DIR__ ) . $this->plugin_name . '.php' );
        $this->loader->add_filter( 'plugin_action_links_' . $plugin_basename, $plugin_admin, 'add_action_links' );
Martin Lees's avatar
Martin Lees committed
164

Martin Lees's avatar
Martin Lees committed
165
166

        $this->loader->add_action('admin_init', $plugin_admin, 'options_update');
167
        $this->loader->add_action( 'transition_post_status', $plugin_admin, 'Steempress_sp_post', 15, 3 );
Martin Lees's avatar
Martin Lees committed
168

Martin Lees's avatar
Martin Lees committed
169

Martin Lees's avatar
Martin Lees committed
170
        $this->loader->add_filter( 'bulk_actions-edit-post', $plugin_admin,'steempress_sp_bulk_update_action' );
171
172
        $this->loader->add_filter( 'bulk_actions-edit-post', $plugin_admin,'steempress_sp_bulk_publish_action' );
        $this->loader->add_filter( 'handle_bulk_actions-edit-post', $plugin_admin,'steempress_sp_bulk_publish_handler', 10, 3 );
Martin Lees's avatar
Martin Lees committed
173
        $this->loader->add_filter( 'handle_bulk_actions-edit-post', $plugin_admin,'steempress_sp_bulk_update_handler', 10, 3 );
174
        $this->loader->add_action( 'admin_notices', $plugin_admin,'steempress_sp_bulk_publish_notice' );
Martin Lees's avatar
Martin Lees committed
175
        $this->loader->add_action( 'admin_notices', $plugin_admin,'steempress_sp_bulk_update_notice' );
Martin Lees's avatar
Martin Lees committed
176
177


Martin Lees's avatar
Martin Lees committed
178
        $this->loader->add_action( 'post_submitbox_misc_actions', $plugin_admin,'createSteemPublishField' );
179
        $this->loader->add_action( 'post_submitbox_misc_actions', $plugin_admin,'create_update_checkbox' );
180
        $this->loader->add_action( 'save_post', $plugin_admin,'saveSteemPublishField',8);
181
        $this->loader->add_action('add_meta_boxes',$plugin_admin,  'steempress_sp_add_custom_box');
Martin Lees's avatar
Martin Lees committed
182
        $this->loader->add_action('save_post', $plugin_admin,  'steempress_sp_save_post_data');
Martin Lees's avatar
Martin Lees committed
183
184


Martin Lees's avatar
Martin Lees committed
185
    }
Martin Lees's avatar
Martin Lees committed
186

Martin Lees's avatar
Martin Lees committed
187
188


Martin Lees's avatar
Martin Lees committed
189
190
191
192
193
194
195
196
197
	/**
	 * Register all of the hooks related to the public-facing functionality
	 * of the plugin.
	 *
	 * @since    1.0.0
	 * @access   private
	 */
	private function define_public_hooks() {

Martin Lees's avatar
Martin Lees committed
198
		$plugin_public = new Steempress_sp_Public( $this->get_plugin_name(), $this->get_version() );
Martin Lees's avatar
Martin Lees committed
199
        $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' );
Martin Lees's avatar
Martin Lees committed
200
		$this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
201
        $this->loader->add_filter('the_content',$plugin_public, 'steempress_sp_comments');
Martin Lees's avatar
Martin Lees committed
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
	}

	/**
	 * Run the loader to execute all of the hooks with WordPress.
	 *
	 * @since    1.0.0
	 */
	public function run() {
		$this->loader->run();
	}

	/**
	 * The name of the plugin used to uniquely identify it within the context of
	 * WordPress and to define internationalization functionality.
	 *
	 * @since     1.0.0
	 * @return    string    The name of the plugin.
	 */
	public function get_plugin_name() {
		return $this->plugin_name;
	}

	/**
	 * The reference to the class that orchestrates the hooks with the plugin.
	 *
	 * @since     1.0.0
Martin Lees's avatar
Martin Lees committed
228
	 * @return    Steempress_sp_Loader    Orchestrates the hooks of the plugin.
Martin Lees's avatar
Martin Lees committed
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
	 */
	public function get_loader() {
		return $this->loader;
	}

	/**
	 * Retrieve the version number of the plugin.
	 *
	 * @since     1.0.0
	 * @return    string    The version number of the plugin.
	 */
	public function get_version() {
		return $this->version;
	}

Martin Lees's avatar
Martin Lees committed
244

Martin Lees's avatar
Martin Lees committed
245
}