@@ -7,9 +7,9 @@ discard block |
||
| 7 | 7 | * @author Nirjhar Lo |
| 8 | 8 | * @package wp-plugin-framework |
| 9 | 9 | */ |
| 10 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 10 | +if ( ! defined('ABSPATH')) exit; |
|
| 11 | 11 | |
| 12 | -if ( ! class_exists( 'Script' ) ) { |
|
| 12 | +if ( ! class_exists('Script')) { |
|
| 13 | 13 | |
| 14 | 14 | final class Script { |
| 15 | 15 | |
@@ -21,9 +21,9 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | public function __construct() { |
| 23 | 23 | |
| 24 | - add_action( 'admin_head', array( $this, 'data_table_css' ) ); |
|
| 25 | - add_action( 'admin_enqueue_scripts', array( $this, 'backend_scripts' ) ); |
|
| 26 | - add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) ); |
|
| 24 | + add_action('admin_head', array($this, 'data_table_css')); |
|
| 25 | + add_action('admin_enqueue_scripts', array($this, 'backend_scripts')); |
|
| 26 | + add_action('wp_enqueue_scripts', array($this, 'frontend_scripts')); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | |
@@ -55,10 +55,10 @@ discard block |
||
| 55 | 55 | // Set condition to add script |
| 56 | 56 | // if ( ! isset( $_GET['page'] ) || $_GET['page'] != 'pageName' ) return; |
| 57 | 57 | |
| 58 | - wp_enqueue_script( 'jsName', PLUGIN_JS . 'ui.js', array() ); |
|
| 59 | - wp_localize_script( 'jsName', 'ajax', array( 'ajax_url' => admin_url('admin-ajax.php') ) ); |
|
| 58 | + wp_enqueue_script('jsName', PLUGIN_JS . 'ui.js', array()); |
|
| 59 | + wp_localize_script('jsName', 'ajax', array('ajax_url' => admin_url('admin-ajax.php'))); |
|
| 60 | 60 | |
| 61 | - wp_enqueue_style( 'cssName', PLUGIN_CSS . 'css.css' ); |
|
| 61 | + wp_enqueue_style('cssName', PLUGIN_CSS . 'css.css'); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | |
@@ -69,10 +69,10 @@ discard block |
||
| 69 | 69 | */ |
| 70 | 70 | public function frontend_scripts() { |
| 71 | 71 | |
| 72 | - wp_enqueue_script( 'jsName', PLUGIN_JS . 'ui.js', array() ); |
|
| 73 | - wp_localize_script( 'jsName', 'ajax', array( 'ajax_url' => admin_url('admin-ajax.php') ) ); |
|
| 72 | + wp_enqueue_script('jsName', PLUGIN_JS . 'ui.js', array()); |
|
| 73 | + wp_localize_script('jsName', 'ajax', array('ajax_url' => admin_url('admin-ajax.php'))); |
|
| 74 | 74 | |
| 75 | - wp_enqueue_style( 'cssName', PLUGIN_CSS . 'css.css' ); |
|
| 75 | + wp_enqueue_style('cssName', PLUGIN_CSS . 'css.css'); |
|
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | } ?> |
@@ -7,7 +7,9 @@ |
||
| 7 | 7 | * @author Nirjhar Lo |
| 8 | 8 | * @package wp-plugin-framework |
| 9 | 9 | */ |
| 10 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 10 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 11 | + exit; |
|
| 12 | +} |
|
| 11 | 13 | |
| 12 | 14 | if ( ! class_exists( 'Script' ) ) { |
| 13 | 15 | |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace NirjharLo\WP_Plugin_Framework\Lib; |
| 3 | 3 | |
| 4 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 4 | +if ( ! defined('ABSPATH')) exit; |
|
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | 7 | * Add Cron schedules and cron task callback |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | * @author Nirjhar Lo |
| 10 | 10 | * @package wp-plugin-framework |
| 11 | 11 | */ |
| 12 | -if ( ! class_exists( 'Cron' ) ) { |
|
| 12 | +if ( ! class_exists('Cron')) { |
|
| 13 | 13 | |
| 14 | 14 | final class Cron { |
| 15 | 15 | |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | public function __construct() { |
| 23 | 23 | |
| 24 | 24 | //Add cron schedules |
| 25 | - add_filter('cron_schedules', array( $this, 'cron_schedules' ) ); |
|
| 25 | + add_filter('cron_schedules', array($this, 'cron_schedules')); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * |
| 32 | 32 | * @return Void |
| 33 | 33 | */ |
| 34 | - public function cron_schedules( $schedules ) { |
|
| 34 | + public function cron_schedules($schedules) { |
|
| 35 | 35 | |
| 36 | 36 | $prefix = 'prefix_'; // Avoid conflict with other crons. Example Reference: cron_30_mins |
| 37 | 37 | |
@@ -52,13 +52,13 @@ discard block |
||
| 52 | 52 | ); |
| 53 | 53 | |
| 54 | 54 | /* Add each custom schedule into the cron job system. */ |
| 55 | - foreach($schedule_options as $schedule_key => $schedule){ |
|
| 55 | + foreach ($schedule_options as $schedule_key => $schedule) { |
|
| 56 | 56 | |
| 57 | - if(!isset($schedules[$prefix.$schedule_key])) { |
|
| 57 | + if ( ! isset($schedules[$prefix . $schedule_key])) { |
|
| 58 | 58 | |
| 59 | - $schedules[$prefix.$schedule_key] = array( |
|
| 59 | + $schedules[$prefix . $schedule_key] = array( |
|
| 60 | 60 | 'interval' => $schedule['interval'], |
| 61 | - 'display' => __( 'Every '.$schedule['display'] ) |
|
| 61 | + 'display' => __('Every ' . $schedule['display']) |
|
| 62 | 62 | ); |
| 63 | 63 | } |
| 64 | 64 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public function schedule_task($task) { |
| 76 | 76 | |
| 77 | - if( ! $task ) { |
|
| 77 | + if ( ! $task) { |
|
| 78 | 78 | return false; |
| 79 | 79 | } |
| 80 | 80 | |
@@ -84,17 +84,17 @@ discard block |
||
| 84 | 84 | 'hook' |
| 85 | 85 | ); |
| 86 | 86 | $missing_keys = array(); |
| 87 | - foreach( $required_keys as $key ){ |
|
| 88 | - if( ! array_key_exists( $key, $task ) ) { |
|
| 87 | + foreach ($required_keys as $key) { |
|
| 88 | + if ( ! array_key_exists($key, $task)) { |
|
| 89 | 89 | $missing_keys[] = $key; |
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - if( ! empty( $missing_keys ) ){ |
|
| 93 | + if ( ! empty($missing_keys)) { |
|
| 94 | 94 | return false; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - if( wp_next_scheduled( $task['hook'] ) ){ |
|
| 97 | + if (wp_next_scheduled($task['hook'])) { |
|
| 98 | 98 | wp_clear_scheduled_hook($task['hook']); |
| 99 | 99 | } |
| 100 | 100 | |
@@ -1,7 +1,9 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace NirjharLo\WP_Plugin_Framework\Lib; |
| 3 | 3 | |
| 4 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 4 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 5 | + exit; |
|
| 6 | +} |
|
| 5 | 7 | |
| 6 | 8 | /** |
| 7 | 9 | * Add Cron schedules and cron task callback |
@@ -8,10 +8,10 @@ discard block |
||
| 8 | 8 | * @author Nirjhar Lo |
| 9 | 9 | * @package wp-plugin-framework |
| 10 | 10 | */ |
| 11 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 11 | +if ( ! defined('ABSPATH')) exit; |
|
| 12 | 12 | |
| 13 | 13 | //AJAX helper class |
| 14 | -if ( ! class_exists( 'Ajax' ) ) { |
|
| 14 | +if ( ! class_exists('Ajax')) { |
|
| 15 | 15 | |
| 16 | 16 | final class Ajax { |
| 17 | 17 | |
@@ -23,9 +23,9 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | public function __construct() { |
| 25 | 25 | |
| 26 | - add_action( 'wp_footer', array( $this, 'custom_name_js' ) ); |
|
| 27 | - add_action( 'wp_ajax_custom_name', array( $this, 'custom_name' ) ); |
|
| 28 | - add_action( 'wp_ajax_nopriv_custom_name', array( $this, 'custom_name' ) ); |
|
| 26 | + add_action('wp_footer', array($this, 'custom_name_js')); |
|
| 27 | + add_action('wp_ajax_custom_name', array($this, 'custom_name')); |
|
| 28 | + add_action('wp_ajax_nopriv_custom_name', array($this, 'custom_name')); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | public function form() { ?> |
| 38 | 38 | |
| 39 | 39 | <form id="add_by_ajax" method="POST" action=""> |
| 40 | - <input type="text" name="text_name" placeholder="<?php _e( 'Text', 'textdomain' ); ?>"> |
|
| 40 | + <input type="text" name="text_name" placeholder="<?php _e('Text', 'textdomain'); ?>"> |
|
| 41 | 41 | <input id="ajax_submit" type="submit" name="submit" value="Submit"> |
| 42 | 42 | </form> |
| 43 | 43 | <?php |
@@ -90,8 +90,8 @@ discard block |
||
| 90 | 90 | |
| 91 | 91 | // DO some stuff |
| 92 | 92 | |
| 93 | - $response = array( 'val' => $value ); |
|
| 94 | - echo json_encode( $response ); |
|
| 93 | + $response = array('val' => $value); |
|
| 94 | + echo json_encode($response); |
|
| 95 | 95 | wp_die(); |
| 96 | 96 | } |
| 97 | 97 | } |
@@ -8,7 +8,9 @@ |
||
| 8 | 8 | * @author Nirjhar Lo |
| 9 | 9 | * @package wp-plugin-framework |
| 10 | 10 | */ |
| 11 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 11 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 12 | + exit; |
|
| 13 | +} |
|
| 12 | 14 | |
| 13 | 15 | //AJAX helper class |
| 14 | 16 | if ( ! class_exists( 'Ajax' ) ) { |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | use NirjharLo\WP_Plugin_Framework\Lib\Cron as Cron; |
| 14 | 14 | use NirjharLo\WP_Plugin_Framework\Lib\Script as Script; |
| 15 | 15 | |
| 16 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 16 | +if ( ! defined('ABSPATH')) exit; |
|
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * Main plugin object to define the plugin |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * @author Nirjhar Lo |
| 23 | 23 | * @package wp-plugin-framework |
| 24 | 24 | */ |
| 25 | -if ( ! class_exists( 'PluginLoader' ) ) { |
|
| 25 | +if ( ! class_exists('PluginLoader')) { |
|
| 26 | 26 | |
| 27 | 27 | final class PluginLoader { |
| 28 | 28 | |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | public static function instance() { |
| 85 | 85 | |
| 86 | - if ( is_null( self::$_instance ) ) { |
|
| 86 | + if (is_null(self::$_instance)) { |
|
| 87 | 87 | self::$_instance = new self(); |
| 88 | 88 | self::$_instance->init(); |
| 89 | 89 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | //If CPT exists, include taht and flush the rewrite rules |
| 112 | - if ( class_exists( 'NirjharLo\\WP_Plugin_Framework\\Src\\Cpt' ) ) new Cpt(); |
|
| 112 | + if (class_exists('NirjharLo\\WP_Plugin_Framework\\Src\\Cpt')) new Cpt(); |
|
| 113 | 113 | flush_rewrite_rules(); |
| 114 | 114 | } |
| 115 | 115 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | public function cron_activation() { |
| 123 | 123 | |
| 124 | - if ( class_exists( 'NirjharLo\\WP_Plugin_Framework\\Lib\\Cron' ) ) { |
|
| 124 | + if (class_exists('NirjharLo\\WP_Plugin_Framework\\Lib\\Cron')) { |
|
| 125 | 125 | |
| 126 | 126 | $cron = new Cron(); |
| 127 | 127 | $schedule = $cron->schedule_task( |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | */ |
| 145 | 145 | public function db_install() { |
| 146 | 146 | |
| 147 | - if ( class_exists( 'NirjharLo\\WP_Plugin_Framework\\Src\\Db' ) ) { |
|
| 147 | + if (class_exists('NirjharLo\\WP_Plugin_Framework\\Src\\Db')) { |
|
| 148 | 148 | |
| 149 | 149 | $db = new Db(); |
| 150 | 150 | $db->table = self::$plugin_table; |
@@ -154,15 +154,15 @@ discard block |
||
| 154 | 154 | $db->build(); |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - if (get_option( '_plugin_db_exist') == '0' ) { |
|
| 158 | - add_action( 'admin_notices', array( $this, 'db_error_msg' ) ); |
|
| 157 | + if (get_option('_plugin_db_exist') == '0') { |
|
| 158 | + add_action('admin_notices', array($this, 'db_error_msg')); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | $options = array( |
| 162 | - array( 'option_name', '__value__' ), |
|
| 162 | + array('option_name', '__value__'), |
|
| 163 | 163 | ); |
| 164 | - foreach ( $options as $value ) { |
|
| 165 | - update_option( $value[0], $value[1] ); |
|
| 164 | + foreach ($options as $value) { |
|
| 165 | + update_option($value[0], $value[1]); |
|
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | 168 | |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | public function db_error_msg() { ?> |
| 176 | 176 | |
| 177 | 177 | <div class="notice notice-error is-dismissible"> |
| 178 | - <p><?php _e( 'Database table Not installed correctly.', 'textdomain' ); ?></p> |
|
| 178 | + <p><?php _e('Database table Not installed correctly.', 'textdomain'); ?></p> |
|
| 179 | 179 | </div> |
| 180 | 180 | <?php |
| 181 | 181 | } |
@@ -191,13 +191,13 @@ discard block |
||
| 191 | 191 | $table_name = self::$plugin_table; |
| 192 | 192 | |
| 193 | 193 | global $wpdb; |
| 194 | - $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}$table_name" ); |
|
| 194 | + $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}$table_name"); |
|
| 195 | 195 | |
| 196 | 196 | $options = array( |
| 197 | 197 | '_plugin_db_exist' |
| 198 | 198 | ); |
| 199 | - foreach ( $options as $value ) { |
|
| 200 | - delete_option( $value ); |
|
| 199 | + foreach ($options as $value) { |
|
| 200 | + delete_option($value); |
|
| 201 | 201 | } |
| 202 | 202 | } |
| 203 | 203 | |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | */ |
| 221 | 221 | public function custom_cron_hook_cb() { |
| 222 | 222 | |
| 223 | - add_action( 'custom_cron_hook', array( $this, 'do_cron_job_function' ) ); |
|
| 223 | + add_action('custom_cron_hook', array($this, 'do_cron_job_function')); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | */ |
| 232 | 232 | public function cron_uninstall() { |
| 233 | 233 | |
| 234 | - wp_clear_scheduled_hook( 'custom_cron_hook' ); |
|
| 234 | + wp_clear_scheduled_hook('custom_cron_hook'); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | |
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | */ |
| 243 | 243 | public function cpt() { |
| 244 | 244 | |
| 245 | - if ( class_exists( 'NirjharLo\\WP_Plugin_Framework\\Src\\Cpt' ) ) new Cpt(); |
|
| 245 | + if (class_exists('NirjharLo\\WP_Plugin_Framework\\Src\\Cpt')) new Cpt(); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | */ |
| 254 | 254 | public function scripts() { |
| 255 | 255 | |
| 256 | - if ( class_exists( 'NirjharLo\\WP_Plugin_Framework\\Lib\\Script' ) ) new Script(); |
|
| 256 | + if (class_exists('NirjharLo\\WP_Plugin_Framework\\Lib\\Script')) new Script(); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | */ |
| 265 | 265 | public function settings() { |
| 266 | 266 | |
| 267 | - if ( class_exists( 'NirjharLo\\WP_Plugin_Framework\\Src\\Settings' ) ) new Settings(); |
|
| 267 | + if (class_exists('NirjharLo\\WP_Plugin_Framework\\Src\\Settings')) new Settings(); |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | */ |
| 276 | 276 | public function widgets() { |
| 277 | 277 | |
| 278 | - if ( class_exists( 'NirjharLo\\WP_Plugin_Framework\\Src\\Widget' ) ) new Widget(); |
|
| 278 | + if (class_exists('NirjharLo\\WP_Plugin_Framework\\Src\\Widget')) new Widget(); |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | */ |
| 287 | 287 | public function metabox() { |
| 288 | 288 | |
| 289 | - if ( class_exists( 'NirjharLo\\WP_Plugin_Framework\\Src\\Metabox' ) ) new Metabox(); |
|
| 289 | + if (class_exists('NirjharLo\\WP_Plugin_Framework\\Src\\Metabox')) new Metabox(); |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | */ |
| 298 | 298 | public function shortcode() { |
| 299 | 299 | |
| 300 | - if ( class_exists( 'NirjharLo\\WP_Plugin_Framework\\Src\\Shortcode' ) ) new Shortcode(); |
|
| 300 | + if (class_exists('NirjharLo\\WP_Plugin_Framework\\Src\\Shortcode')) new Shortcode(); |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | */ |
| 309 | 309 | public function rest_api() { |
| 310 | 310 | |
| 311 | - if ( class_exists( 'NirjharLo\\WP_Plugin_Framework\\Src\\RestApi' ) ) new RestApi(); |
|
| 311 | + if (class_exists('NirjharLo\\WP_Plugin_Framework\\Src\\RestApi')) new RestApi(); |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | |
@@ -317,20 +317,20 @@ discard block |
||
| 317 | 317 | * |
| 318 | 318 | * @return Void |
| 319 | 319 | */ |
| 320 | - public function prevent_unauthorized_rest_access( $result ) { |
|
| 320 | + public function prevent_unauthorized_rest_access($result) { |
|
| 321 | 321 | // If a previous authentication check was applied, |
| 322 | 322 | // pass that result along without modification. |
| 323 | - if ( true === $result || is_wp_error( $result ) ) { |
|
| 323 | + if (true === $result || is_wp_error($result)) { |
|
| 324 | 324 | return $result; |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | // No authentication has been performed yet. |
| 328 | 328 | // Return an error if user is not logged in. |
| 329 | - if ( ! is_user_logged_in() ) { |
|
| 329 | + if ( ! is_user_logged_in()) { |
|
| 330 | 330 | return new WP_Error( |
| 331 | 331 | 'rest_not_logged_in', |
| 332 | - __( 'You are not currently logged in.' ), |
|
| 333 | - array( 'status' => 401 ) |
|
| 332 | + __('You are not currently logged in.'), |
|
| 333 | + array('status' => 401) |
|
| 334 | 334 | ); |
| 335 | 335 | } |
| 336 | 336 | |
@@ -345,18 +345,18 @@ discard block |
||
| 345 | 345 | */ |
| 346 | 346 | public function init() { |
| 347 | 347 | |
| 348 | - register_activation_hook( PLUGIN_FILE, array( $this, 'db_install' ) ); |
|
| 349 | - register_activation_hook( PLUGIN_FILE, array( $this, 'cron_activation' ) ); |
|
| 348 | + register_activation_hook(PLUGIN_FILE, array($this, 'db_install')); |
|
| 349 | + register_activation_hook(PLUGIN_FILE, array($this, 'cron_activation')); |
|
| 350 | 350 | |
| 351 | 351 | //remove the DB and CORN upon uninstallation |
| 352 | 352 | //using $this won't work here. |
| 353 | - register_uninstall_hook( PLUGIN_FILE, array( 'NirjharLo\\WP_Plugin_Framework\\PluginLoader', 'db_uninstall' ) ); |
|
| 354 | - register_uninstall_hook( PLUGIN_FILE, array( 'NirjharLo\\WP_Plugin_Framework\\PluginLoader', 'cron_uninstall' ) ); |
|
| 353 | + register_uninstall_hook(PLUGIN_FILE, array('NirjharLo\\WP_Plugin_Framework\\PluginLoader', 'db_uninstall')); |
|
| 354 | + register_uninstall_hook(PLUGIN_FILE, array('NirjharLo\\WP_Plugin_Framework\\PluginLoader', 'cron_uninstall')); |
|
| 355 | 355 | |
| 356 | - add_filter( 'rest_authentication_errors', array( $this, 'prevent_unauthorized_rest_access' ) ); |
|
| 356 | + add_filter('rest_authentication_errors', array($this, 'prevent_unauthorized_rest_access')); |
|
| 357 | 357 | |
| 358 | - add_action( 'init', array( $this, 'installation' ) ); |
|
| 359 | - add_action( 'init', array( $this, 'cpt' ) ); |
|
| 358 | + add_action('init', array($this, 'installation')); |
|
| 359 | + add_action('init', array($this, 'cpt')); |
|
| 360 | 360 | |
| 361 | 361 | $this->custom_cron_hook_cb(); |
| 362 | 362 | |
@@ -13,7 +13,9 @@ discard block |
||
| 13 | 13 | use NirjharLo\WP_Plugin_Framework\Lib\Cron as Cron; |
| 14 | 14 | use NirjharLo\WP_Plugin_Framework\Lib\Script as Script; |
| 15 | 15 | |
| 16 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 16 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 17 | + exit; |
|
| 18 | +} |
|
| 17 | 19 | |
| 18 | 20 | /** |
| 19 | 21 | * Main plugin object to define the plugin |
@@ -109,7 +111,9 @@ discard block |
||
| 109 | 111 | } |
| 110 | 112 | |
| 111 | 113 | //If CPT exists, include taht and flush the rewrite rules |
| 112 | - if ( class_exists( 'NirjharLo\\WP_Plugin_Framework\\Src\\Cpt' ) ) new Cpt(); |
|
| 114 | + if ( class_exists( 'NirjharLo\\WP_Plugin_Framework\\Src\\Cpt' ) ) { |
|
| 115 | + new Cpt(); |
|
| 116 | + } |
|
| 113 | 117 | flush_rewrite_rules(); |
| 114 | 118 | } |
| 115 | 119 | |
@@ -242,7 +246,9 @@ discard block |
||
| 242 | 246 | */ |
| 243 | 247 | public function cpt() { |
| 244 | 248 | |
| 245 | - if ( class_exists( 'NirjharLo\\WP_Plugin_Framework\\Src\\Cpt' ) ) new Cpt(); |
|
| 249 | + if ( class_exists( 'NirjharLo\\WP_Plugin_Framework\\Src\\Cpt' ) ) { |
|
| 250 | + new Cpt(); |
|
| 251 | + } |
|
| 246 | 252 | } |
| 247 | 253 | |
| 248 | 254 | |
@@ -253,7 +259,9 @@ discard block |
||
| 253 | 259 | */ |
| 254 | 260 | public function scripts() { |
| 255 | 261 | |
| 256 | - if ( class_exists( 'NirjharLo\\WP_Plugin_Framework\\Lib\\Script' ) ) new Script(); |
|
| 262 | + if ( class_exists( 'NirjharLo\\WP_Plugin_Framework\\Lib\\Script' ) ) { |
|
| 263 | + new Script(); |
|
| 264 | + } |
|
| 257 | 265 | } |
| 258 | 266 | |
| 259 | 267 | |
@@ -264,7 +272,9 @@ discard block |
||
| 264 | 272 | */ |
| 265 | 273 | public function settings() { |
| 266 | 274 | |
| 267 | - if ( class_exists( 'NirjharLo\\WP_Plugin_Framework\\Src\\Settings' ) ) new Settings(); |
|
| 275 | + if ( class_exists( 'NirjharLo\\WP_Plugin_Framework\\Src\\Settings' ) ) { |
|
| 276 | + new Settings(); |
|
| 277 | + } |
|
| 268 | 278 | } |
| 269 | 279 | |
| 270 | 280 | |
@@ -275,7 +285,9 @@ discard block |
||
| 275 | 285 | */ |
| 276 | 286 | public function widgets() { |
| 277 | 287 | |
| 278 | - if ( class_exists( 'NirjharLo\\WP_Plugin_Framework\\Src\\Widget' ) ) new Widget(); |
|
| 288 | + if ( class_exists( 'NirjharLo\\WP_Plugin_Framework\\Src\\Widget' ) ) { |
|
| 289 | + new Widget(); |
|
| 290 | + } |
|
| 279 | 291 | } |
| 280 | 292 | |
| 281 | 293 | |
@@ -286,7 +298,9 @@ discard block |
||
| 286 | 298 | */ |
| 287 | 299 | public function metabox() { |
| 288 | 300 | |
| 289 | - if ( class_exists( 'NirjharLo\\WP_Plugin_Framework\\Src\\Metabox' ) ) new Metabox(); |
|
| 301 | + if ( class_exists( 'NirjharLo\\WP_Plugin_Framework\\Src\\Metabox' ) ) { |
|
| 302 | + new Metabox(); |
|
| 303 | + } |
|
| 290 | 304 | } |
| 291 | 305 | |
| 292 | 306 | |
@@ -297,7 +311,9 @@ discard block |
||
| 297 | 311 | */ |
| 298 | 312 | public function shortcode() { |
| 299 | 313 | |
| 300 | - if ( class_exists( 'NirjharLo\\WP_Plugin_Framework\\Src\\Shortcode' ) ) new Shortcode(); |
|
| 314 | + if ( class_exists( 'NirjharLo\\WP_Plugin_Framework\\Src\\Shortcode' ) ) { |
|
| 315 | + new Shortcode(); |
|
| 316 | + } |
|
| 301 | 317 | } |
| 302 | 318 | |
| 303 | 319 | |
@@ -308,7 +324,9 @@ discard block |
||
| 308 | 324 | */ |
| 309 | 325 | public function rest_api() { |
| 310 | 326 | |
| 311 | - if ( class_exists( 'NirjharLo\\WP_Plugin_Framework\\Src\\RestApi' ) ) new RestApi(); |
|
| 327 | + if ( class_exists( 'NirjharLo\\WP_Plugin_Framework\\Src\\RestApi' ) ) { |
|
| 328 | + new RestApi(); |
|
| 329 | + } |
|
| 312 | 330 | } |
| 313 | 331 | |
| 314 | 332 | |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | |
| 4 | 4 | use NirjharLo\WP_Plugin_Framework\Lib\Table as Table; |
| 5 | 5 | |
| 6 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 6 | +if ( ! defined('ABSPATH')) exit; |
|
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * Backend settings page class, can have settings fields or data table |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | * @author Nirjhar Lo |
| 12 | 12 | * @package wp-plugin-framework |
| 13 | 13 | */ |
| 14 | -if ( ! class_exists( 'Settings' ) ) { |
|
| 14 | +if ( ! class_exists('Settings')) { |
|
| 15 | 15 | |
| 16 | 16 | class Settings { |
| 17 | 17 | |
@@ -60,14 +60,14 @@ discard block |
||
| 60 | 60 | public function __construct() { |
| 61 | 61 | |
| 62 | 62 | $this->capability = 'manage_options'; |
| 63 | - $this->menu_page = array( 'name' => '', 'heading' => '', 'slug' => '' ); |
|
| 63 | + $this->menu_page = array('name' => '', 'heading' => '', 'slug' => ''); |
|
| 64 | 64 | $this->sub_menu_page = array( |
| 65 | 65 | 'name' => '', |
| 66 | 66 | 'heading' => '', |
| 67 | 67 | 'slug' => '', |
| 68 | 68 | 'parent_slug' => '', |
| 69 | - 'help' => '',//true/false, |
|
| 70 | - 'screen' => '',//true/false |
|
| 69 | + 'help' => '', //true/false, |
|
| 70 | + 'screen' => '', //true/false |
|
| 71 | 71 | ); |
| 72 | 72 | $this->helpData = array( |
| 73 | 73 | array( |
@@ -76,11 +76,11 @@ discard block |
||
| 76 | 76 | 'info' => array( |
| 77 | 77 | array( |
| 78 | 78 | 'id' => 'helpId', |
| 79 | - 'title' => __( 'Title', 'textdomain' ), |
|
| 80 | - 'content' => __( 'Description', 'textdomain' ), |
|
| 79 | + 'title' => __('Title', 'textdomain'), |
|
| 80 | + 'content' => __('Description', 'textdomain'), |
|
| 81 | 81 | ), |
| 82 | 82 | ), |
| 83 | - 'link' => '<p><a href="#">' . __( 'helpLink', 'textdomain' ) . '</a></p>', |
|
| 83 | + 'link' => '<p><a href="#">' . __('helpLink', 'textdomain') . '</a></p>', |
|
| 84 | 84 | ) |
| 85 | 85 | ) |
| 86 | 86 | ); |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | $this->menu_page['heading'], |
| 112 | 112 | $this->capability, |
| 113 | 113 | $this->menu_page['slug'], |
| 114 | - array( $this, 'menu_page_callback' ) |
|
| 114 | + array($this, 'menu_page_callback') |
|
| 115 | 115 | ); |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | */ |
| 125 | 125 | public function sub_menu_page() { |
| 126 | 126 | |
| 127 | - if ( $this->sub_menu_page ) { |
|
| 128 | - foreach ( $this->sub_menu_page as $page ) { |
|
| 127 | + if ($this->sub_menu_page) { |
|
| 128 | + foreach ($this->sub_menu_page as $page) { |
|
| 129 | 129 | $hook = add_submenu_page( |
| 130 | 130 | $page['parent_slug'], |
| 131 | 131 | $page['name'], |
@@ -134,13 +134,13 @@ discard block |
||
| 134 | 134 | // For the first submenu page, slug should be same as menupage. |
| 135 | 135 | $page['slug'], |
| 136 | 136 | // For the first submenu page, callback should be same as menupage. |
| 137 | - array( $this, 'menu_page_callback' ) |
|
| 137 | + array($this, 'menu_page_callback') |
|
| 138 | 138 | ); |
| 139 | - if ( $page['help'] ) { |
|
| 140 | - add_action( 'load-' . $hook, array( $this, 'help_tabs' ) ); |
|
| 139 | + if ($page['help']) { |
|
| 140 | + add_action('load-' . $hook, array($this, 'help_tabs')); |
|
| 141 | 141 | } |
| 142 | - if ( $page['screen'] ) { |
|
| 143 | - add_action( 'load-' . $hook, array( $this, 'screen_option' ) ); |
|
| 142 | + if ($page['screen']) { |
|
| 143 | + add_action('load-' . $hook, array($this, 'screen_option')); |
|
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | } |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | break; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - if ( $output ) return $output; // Related to PLUGIN_TABLE() |
|
| 170 | + if ($output) return $output; // Related to PLUGIN_TABLE() |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | |
@@ -180,11 +180,11 @@ discard block |
||
| 180 | 180 | |
| 181 | 181 | $option = 'per_page'; |
| 182 | 182 | $args = array( |
| 183 | - 'label' => __( 'Show per page', 'textdomain' ), |
|
| 183 | + 'label' => __('Show per page', 'textdomain'), |
|
| 184 | 184 | 'default' => 10, |
| 185 | 185 | 'option' => 'option_name_per_page' // Related to PLUGIN_TABLE() |
| 186 | 186 | ); |
| 187 | - add_screen_option( $option, $args ); |
|
| 187 | + add_screen_option($option, $args); |
|
| 188 | 188 | $this->table = new Table(); // Source /lib/table.php |
| 189 | 189 | } |
| 190 | 190 | |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | <form method="post" action=""> |
| 208 | 208 | <?php settings_fields("settings_id"); |
| 209 | 209 | do_settings_sections("settings_name"); |
| 210 | - submit_button( __( 'Save', 'textdomain' ), 'primary', 'id' ); ?> |
|
| 210 | + submit_button(__('Save', 'textdomain'), 'primary', 'id'); ?> |
|
| 211 | 211 | </form> |
| 212 | 212 | |
| 213 | 213 | <?php |
@@ -235,10 +235,10 @@ discard block |
||
| 235 | 235 | foreach ($this->helpData as $value) { |
| 236 | 236 | if ($_GET['page'] == $value['slug']) { |
| 237 | 237 | $this->screen = get_current_screen(); |
| 238 | - foreach( $value['info'] as $key ) { |
|
| 239 | - $this->screen->add_help_tab( $key ); |
|
| 238 | + foreach ($value['info'] as $key) { |
|
| 239 | + $this->screen->add_help_tab($key); |
|
| 240 | 240 | } |
| 241 | - $this->screen->set_help_sidebar( $value['link'] ); |
|
| 241 | + $this->screen->set_help_sidebar($value['link']); |
|
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | 244 | } |
@@ -251,10 +251,10 @@ discard block |
||
| 251 | 251 | */ |
| 252 | 252 | public function add_settings() { |
| 253 | 253 | |
| 254 | - add_settings_section( 'settings_id', __( 'Section Name', 'textdomain' ), array( $this,'section_cb' ), 'settings_name' ); |
|
| 254 | + add_settings_section('settings_id', __('Section Name', 'textdomain'), array($this, 'section_cb'), 'settings_name'); |
|
| 255 | 255 | |
| 256 | - register_setting( 'settings_id', 'settings_field_name' ); |
|
| 257 | - add_settings_field( 'settings_field_name', __( 'Field Name', 'textdomain' ), array( $this, 'settings_field_cb' ), 'settings_name', 'settings_id' ); |
|
| 256 | + register_setting('settings_id', 'settings_field_name'); |
|
| 257 | + add_settings_field('settings_field_name', __('Field Name', 'textdomain'), array($this, 'settings_field_cb'), 'settings_name', 'settings_id'); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | */ |
| 266 | 266 | public function section_cb() { |
| 267 | 267 | |
| 268 | - echo '<p class="description">' . __( 'Set up settings', 'textdomain' ) . '</p>'; |
|
| 268 | + echo '<p class="description">' . __('Set up settings', 'textdomain') . '</p>'; |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | |
@@ -3,7 +3,9 @@ discard block |
||
| 3 | 3 | |
| 4 | 4 | use NirjharLo\WP_Plugin_Framework\Lib\Table as Table; |
| 5 | 5 | |
| 6 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 6 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 7 | + exit; |
|
| 8 | +} |
|
| 7 | 9 | |
| 8 | 10 | /** |
| 9 | 11 | * Backend settings page class, can have settings fields or data table |
@@ -167,7 +169,10 @@ discard block |
||
| 167 | 169 | break; |
| 168 | 170 | } |
| 169 | 171 | |
| 170 | - if ( $output ) return $output; // Related to PLUGIN_TABLE() |
|
| 172 | + if ( $output ) { |
|
| 173 | + return $output; |
|
| 174 | + } |
|
| 175 | + // Related to PLUGIN_TABLE() |
|
| 171 | 176 | } |
| 172 | 177 | |
| 173 | 178 | |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace NirjharLo\WP_Plugin_Framework\Src; |
| 3 | 3 | |
| 4 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 4 | +if ( ! defined('ABSPATH')) exit; |
|
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | 7 | * Build a sample metabox in editor screen |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | * @author Nirjhar Lo |
| 10 | 10 | * @package wp-plugin-framework |
| 11 | 11 | */ |
| 12 | -if ( ! class_exists( 'Metabox' ) ) { |
|
| 12 | +if ( ! class_exists('Metabox')) { |
|
| 13 | 13 | |
| 14 | 14 | final class Metabox { |
| 15 | 15 | |
@@ -22,8 +22,8 @@ discard block |
||
| 22 | 22 | public function __construct() { |
| 23 | 23 | |
| 24 | 24 | //Adding the metabox. For custom post type use "add_meta_boxes_posttype" action |
| 25 | - add_action( 'add_meta_boxes', array( $this, 'register' ) ); |
|
| 26 | - add_action( 'save_post', array( $this, 'save' ), 10, 2 ); |
|
| 25 | + add_action('add_meta_boxes', array($this, 'register')); |
|
| 26 | + add_action('save_post', array($this, 'save'), 10, 2); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | |
@@ -36,8 +36,8 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | add_meta_box( |
| 38 | 38 | 'meta-box-id', |
| 39 | - esc_html__( 'MetaBox Title', 'textdomain' ), |
|
| 40 | - array( $this, 'render' ), |
|
| 39 | + esc_html__('MetaBox Title', 'textdomain'), |
|
| 40 | + array($this, 'render'), |
|
| 41 | 41 | // Declare the post type to show meta box |
| 42 | 42 | 'post_type', |
| 43 | 43 | 'normal', |
@@ -53,12 +53,12 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | public function render() { |
| 55 | 55 | |
| 56 | - wp_nonce_field( basename( __FILE__ ), 'metabox_name_nonce' ); ?> |
|
| 56 | + wp_nonce_field(basename(__FILE__), 'metabox_name_nonce'); ?> |
|
| 57 | 57 | |
| 58 | 58 | <p> |
| 59 | - <label for="metabox_name"><?php _e( "Custom Text", 'textdomain' ); ?></label> |
|
| 59 | + <label for="metabox_name"><?php _e("Custom Text", 'textdomain'); ?></label> |
|
| 60 | 60 | <br /> |
| 61 | - <input class="widefat" type="text" name="metabox_field_name" id="metabox_field_name" value="<?php echo esc_attr( get_post_meta( $object->ID, 'metabox_name', true ) ); ?>" /> |
|
| 61 | + <input class="widefat" type="text" name="metabox_field_name" id="metabox_field_name" value="<?php echo esc_attr(get_post_meta($object->ID, 'metabox_name', true)); ?>" /> |
|
| 62 | 62 | </p> |
| 63 | 63 | <?php |
| 64 | 64 | } |
@@ -71,22 +71,22 @@ discard block |
||
| 71 | 71 | * |
| 72 | 72 | * @return Html |
| 73 | 73 | */ |
| 74 | - function save( $post_id, $post ) { |
|
| 74 | + function save($post_id, $post) { |
|
| 75 | 75 | |
| 76 | 76 | //Check if doing autosave |
| 77 | - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; |
|
| 77 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return; |
|
| 78 | 78 | |
| 79 | 79 | //Verify the nonce before proceeding. |
| 80 | - if ( !isset( $_POST['metabox_name_nonce'] ) || !wp_verify_nonce( $_POST['metabox_name_nonce'], basename( __FILE__ ) ) ) return; |
|
| 80 | + if ( ! isset($_POST['metabox_name_nonce']) || ! wp_verify_nonce($_POST['metabox_name_nonce'], basename(__FILE__))) return; |
|
| 81 | 81 | |
| 82 | 82 | //Get the post type object. |
| 83 | - $post_type = get_post_type_object( $post->post_type ); |
|
| 83 | + $post_type = get_post_type_object($post->post_type); |
|
| 84 | 84 | |
| 85 | 85 | //Check if the current user has permission to edit the post. |
| 86 | - if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ) return $post_id; |
|
| 86 | + if ( ! current_user_can($post_type->cap->edit_post, $post_id)) return $post_id; |
|
| 87 | 87 | |
| 88 | - if ( isset( $_POST['metabox_field_name'] ) ) { |
|
| 89 | - update_post_meta( $post_id, 'metabox_field_name', sanitize_text_field($_POST['metabox_field_name']) ); |
|
| 88 | + if (isset($_POST['metabox_field_name'])) { |
|
| 89 | + update_post_meta($post_id, 'metabox_field_name', sanitize_text_field($_POST['metabox_field_name'])); |
|
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | } |
@@ -1,7 +1,9 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace NirjharLo\WP_Plugin_Framework\Src; |
| 3 | 3 | |
| 4 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 4 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 5 | + exit; |
|
| 6 | +} |
|
| 5 | 7 | |
| 6 | 8 | /** |
| 7 | 9 | * Build a sample metabox in editor screen |
@@ -74,16 +76,22 @@ discard block |
||
| 74 | 76 | function save( $post_id, $post ) { |
| 75 | 77 | |
| 76 | 78 | //Check if doing autosave |
| 77 | - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; |
|
| 79 | + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
|
| 80 | + return; |
|
| 81 | + } |
|
| 78 | 82 | |
| 79 | 83 | //Verify the nonce before proceeding. |
| 80 | - if ( !isset( $_POST['metabox_name_nonce'] ) || !wp_verify_nonce( $_POST['metabox_name_nonce'], basename( __FILE__ ) ) ) return; |
|
| 84 | + if ( !isset( $_POST['metabox_name_nonce'] ) || !wp_verify_nonce( $_POST['metabox_name_nonce'], basename( __FILE__ ) ) ) { |
|
| 85 | + return; |
|
| 86 | + } |
|
| 81 | 87 | |
| 82 | 88 | //Get the post type object. |
| 83 | 89 | $post_type = get_post_type_object( $post->post_type ); |
| 84 | 90 | |
| 85 | 91 | //Check if the current user has permission to edit the post. |
| 86 | - if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ) return $post_id; |
|
| 92 | + if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ) { |
|
| 93 | + return $post_id; |
|
| 94 | + } |
|
| 87 | 95 | |
| 88 | 96 | if ( isset( $_POST['metabox_field_name'] ) ) { |
| 89 | 97 | update_post_meta( $post_id, 'metabox_field_name', sanitize_text_field($_POST['metabox_field_name']) ); |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace NirjharLo\WP_Plugin_Framework\Src; |
| 3 | 3 | |
| 4 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 4 | +if ( ! defined('ABSPATH')) exit; |
|
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | 7 | * WP Query class for querying WP database |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | * @author Nirjhar Lo |
| 12 | 12 | * @package wp-plugin-framework |
| 13 | 13 | */ |
| 14 | -if ( ! class_exists( 'Query' ) ) { |
|
| 14 | +if ( ! class_exists('Query')) { |
|
| 15 | 15 | |
| 16 | 16 | class Query { |
| 17 | 17 | |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | $paged = get_query_var('paged') ? get_query_var('paged') : (get_query_var('page') ? get_query_var('page') : 1); |
| 37 | 37 | |
| 38 | 38 | $post_args = $this->post_args($paged); |
| 39 | - $the_query = new WP_Query( $post_args ); |
|
| 39 | + $the_query = new WP_Query($post_args); |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | $user_args = $this->user_args($paged); |
@@ -44,15 +44,15 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | |
| 46 | 46 | // The Loop |
| 47 | - if ( $the_query->have_posts() ) { |
|
| 48 | - while ( $the_query->have_posts() ) { |
|
| 47 | + if ($the_query->have_posts()) { |
|
| 48 | + while ($the_query->have_posts()) { |
|
| 49 | 49 | $the_query->the_post(); |
| 50 | 50 | // Do Stuff |
| 51 | 51 | } // end while |
| 52 | 52 | } // endif |
| 53 | 53 | |
| 54 | - if ( function_exists('wp_pagenavi' ) ) { |
|
| 55 | - wp_pagenavi( array( 'query' => $the_query, 'echo' => true ) );//For user query add param 'type' => 'users' |
|
| 54 | + if (function_exists('wp_pagenavi')) { |
|
| 55 | + wp_pagenavi(array('query' => $the_query, 'echo' => true)); //For user query add param 'type' => 'users' |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | // Reset Post Data |
@@ -65,11 +65,11 @@ discard block |
||
| 65 | 65 | * |
| 66 | 66 | * @return Void |
| 67 | 67 | */ |
| 68 | - public function user_args( $paged ) { |
|
| 68 | + public function user_args($paged) { |
|
| 69 | 69 | |
| 70 | - $offset = ( $paged - 1 ) * $this->display_count; |
|
| 70 | + $offset = ($paged - 1) * $this->display_count; |
|
| 71 | 71 | |
| 72 | - $args = array ( |
|
| 72 | + $args = array( |
|
| 73 | 73 | 'role' => '', // user role |
| 74 | 74 | 'order' => '', //ASC or DESC |
| 75 | 75 | 'fields' => '', // |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | 'count_total' => true, |
| 86 | 86 | 'paged' => $paged, |
| 87 | 87 | 'offset' => $offset, |
| 88 | - 'search' => '*' . esc_attr( $_GET['s'] ) . '*', |
|
| 88 | + 'search' => '*' . esc_attr($_GET['s']) . '*', |
|
| 89 | 89 | 'meta_query' => array( // It supports nested meta query |
| 90 | 90 | 'relation' => 'AND', //or 'OR' |
| 91 | 91 | array( |
@@ -110,11 +110,11 @@ discard block |
||
| 110 | 110 | * |
| 111 | 111 | * @return Void |
| 112 | 112 | */ |
| 113 | - public function post_args( $paged ) { |
|
| 113 | + public function post_args($paged) { |
|
| 114 | 114 | |
| 115 | - $offset = ( $paged - 1 ) * $this->display_count; |
|
| 115 | + $offset = ($paged - 1) * $this->display_count; |
|
| 116 | 116 | |
| 117 | - $args = array ( |
|
| 117 | + $args = array( |
|
| 118 | 118 | 'post_type' => '', // array of type slugs |
| 119 | 119 | 'order' => 'ASC', |
| 120 | 120 | 'fields' => '', // |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | 'count_total' => true, |
| 129 | 129 | 'paged' => $paged, |
| 130 | 130 | 'offset' => $offset, |
| 131 | - 'search' => '*' . esc_attr( $_GET['s'] ) . '*', |
|
| 131 | + 'search' => '*' . esc_attr($_GET['s']) . '*', |
|
| 132 | 132 | 'meta_query' => array( // It supports nested meta query |
| 133 | 133 | 'relation' => 'AND', //or 'OR' |
| 134 | 134 | array( |
@@ -1,7 +1,9 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace NirjharLo\WP_Plugin_Framework\Src; |
| 3 | 3 | |
| 4 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 4 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 5 | + exit; |
|
| 6 | +} |
|
| 5 | 7 | |
| 6 | 8 | /** |
| 7 | 9 | * WP Query class for querying WP database |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace NirjharLo\WP_Plugin_Framework\Src; |
| 3 | 3 | |
| 4 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 4 | +if ( ! defined('ABSPATH')) exit; |
|
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | 7 | * Custom post type class |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | * @author Nirjhar Lo |
| 10 | 10 | * @package wp-plugin-framework |
| 11 | 11 | */ |
| 12 | -if ( ! class_exists( 'Cpt' ) ) { |
|
| 12 | +if ( ! class_exists('Cpt')) { |
|
| 13 | 13 | |
| 14 | 14 | class Cpt { |
| 15 | 15 | |
@@ -37,10 +37,10 @@ discard block |
||
| 37 | 37 | public function __construct() { |
| 38 | 38 | |
| 39 | 39 | $this->labels = $this->labels(); |
| 40 | - $this->args = $this->args( $this->labels ); |
|
| 40 | + $this->args = $this->args($this->labels); |
|
| 41 | 41 | |
| 42 | 42 | $this->taxonomy_labels = $this->taxonomy_labels(); |
| 43 | - $this->taxonomy_args = $this->taxonomy_args( $this->taxonomy_labels ); |
|
| 43 | + $this->taxonomy_args = $this->taxonomy_args($this->taxonomy_labels); |
|
| 44 | 44 | |
| 45 | 45 | //register_post_type( 'cpt_name', $this->args ); |
| 46 | 46 | //add_filter( 'post_updated_messages', array( $this, 'group_updated_messages' ) ); |
@@ -57,19 +57,19 @@ discard block |
||
| 57 | 57 | public function labels() { |
| 58 | 58 | |
| 59 | 59 | $labels = array( |
| 60 | - 'name' => _x( '', 'Post Type General Name', 'textdomain' ), |
|
| 61 | - 'singular_name' => _x( '', 'Post Type Singular Name', 'textdomain' ), |
|
| 62 | - 'menu_name' => __( '', 'textdomain' ), |
|
| 63 | - 'parent_item_colon' => __( '', 'textdomain' ), |
|
| 64 | - 'all_items' => __( '', 'textdomain' ), |
|
| 65 | - 'view_item' => __( '', 'textdomain' ), |
|
| 66 | - 'add_new_item' => __( '', 'textdomain' ), |
|
| 67 | - 'add_new' => __( '', 'textdomain' ), |
|
| 68 | - 'edit_item' => __( '', 'textdomain' ), |
|
| 69 | - 'update_item' => __( '', 'textdomain' ), |
|
| 70 | - 'search_items' => __( '', 'textdomain' ), |
|
| 71 | - 'not_found' => __( '', 'textdomain' ), |
|
| 72 | - 'not_found_in_trash' => __( '', 'textdomain' ), |
|
| 60 | + 'name' => _x('', 'Post Type General Name', 'textdomain'), |
|
| 61 | + 'singular_name' => _x('', 'Post Type Singular Name', 'textdomain'), |
|
| 62 | + 'menu_name' => __('', 'textdomain'), |
|
| 63 | + 'parent_item_colon' => __('', 'textdomain'), |
|
| 64 | + 'all_items' => __('', 'textdomain'), |
|
| 65 | + 'view_item' => __('', 'textdomain'), |
|
| 66 | + 'add_new_item' => __('', 'textdomain'), |
|
| 67 | + 'add_new' => __('', 'textdomain'), |
|
| 68 | + 'edit_item' => __('', 'textdomain'), |
|
| 69 | + 'update_item' => __('', 'textdomain'), |
|
| 70 | + 'search_items' => __('', 'textdomain'), |
|
| 71 | + 'not_found' => __('', 'textdomain'), |
|
| 72 | + 'not_found_in_trash' => __('', 'textdomain'), |
|
| 73 | 73 | ); |
| 74 | 74 | |
| 75 | 75 | return $labels; |
@@ -83,17 +83,17 @@ discard block |
||
| 83 | 83 | * |
| 84 | 84 | * @return Array |
| 85 | 85 | */ |
| 86 | - public function args( $labels ) { |
|
| 86 | + public function args($labels) { |
|
| 87 | 87 | |
| 88 | 88 | $args = array( |
| 89 | - 'label' => __( '', 'textdomain' ), |
|
| 90 | - 'description' => __( '', 'textdomain' ), |
|
| 89 | + 'label' => __('', 'textdomain'), |
|
| 90 | + 'description' => __('', 'textdomain'), |
|
| 91 | 91 | 'labels' => $labels, |
| 92 | - 'supports' => array( 'title', 'editor', 'thumbnail' ), |
|
| 93 | - 'taxonomies' => array( 'custom_tax', 'post_tag' ), |
|
| 92 | + 'supports' => array('title', 'editor', 'thumbnail'), |
|
| 93 | + 'taxonomies' => array('custom_tax', 'post_tag'), |
|
| 94 | 94 | 'hierarchical' => true, |
| 95 | 95 | 'public' => true, |
| 96 | - 'rewrite' => array( 'slug' => 'slug_name' ), |
|
| 96 | + 'rewrite' => array('slug' => 'slug_name'), |
|
| 97 | 97 | 'show_ui' => true, |
| 98 | 98 | 'show_in_menu' => true, |
| 99 | 99 | 'menu_icon' => 'data:image/svg+xml;base64,' . self::$menu_svg, |
@@ -121,22 +121,22 @@ discard block |
||
| 121 | 121 | * |
| 122 | 122 | * @return Array |
| 123 | 123 | */ |
| 124 | - public function cpt_updated_messages( $messages ) { |
|
| 124 | + public function cpt_updated_messages($messages) { |
|
| 125 | 125 | |
| 126 | 126 | global $post, $post_ID; |
| 127 | 127 | |
| 128 | 128 | $messages['cpt_name'] = array( |
| 129 | 129 | 0 => '', |
| 130 | - 1 => sprintf( __( 'CPT updated. <a href="%s">View CPT</a>', 'textdomain' ), esc_url( get_permalink( $post_ID ) ) ), |
|
| 131 | - 2 => __( 'field updated.', 'textdomain' ), |
|
| 132 | - 3 => __( 'field deleted.', 'textdomain' ), |
|
| 133 | - 4 => __( 'CPT updated.', 'textdomain' ), |
|
| 134 | - 5 => ( isset( $_GET['revision'] ) ? sprintf( __( 'CPT restored to revision from %s', 'textdomain' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false ), |
|
| 135 | - 6 => sprintf( __( 'CPT published. <a href="%s">View Cpt</a>', 'textdomain' ), esc_url( get_permalink( $post_ID ) ) ), |
|
| 136 | - 7 => __( 'CPT saved.', 'textdomain' ), |
|
| 137 | - 8 => sprintf( __( 'CPT submitted. <a target="_blank" href="%s">Preview cpt</a>', 'textdomain' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ), |
|
| 138 | - 9 => sprintf( __( 'CPT scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview cpt</a>', 'textdomain' ), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post_ID ) ) ), |
|
| 139 | - 10 => sprintf( __( 'CPT draft updated. <a target="_blank" href="%s">Preview cpt</a>', 'textdomain' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ), |
|
| 130 | + 1 => sprintf(__('CPT updated. <a href="%s">View CPT</a>', 'textdomain'), esc_url(get_permalink($post_ID))), |
|
| 131 | + 2 => __('field updated.', 'textdomain'), |
|
| 132 | + 3 => __('field deleted.', 'textdomain'), |
|
| 133 | + 4 => __('CPT updated.', 'textdomain'), |
|
| 134 | + 5 => (isset($_GET['revision']) ? sprintf(__('CPT restored to revision from %s', 'textdomain'), wp_post_revision_title((int) $_GET['revision'], false)) : false), |
|
| 135 | + 6 => sprintf(__('CPT published. <a href="%s">View Cpt</a>', 'textdomain'), esc_url(get_permalink($post_ID))), |
|
| 136 | + 7 => __('CPT saved.', 'textdomain'), |
|
| 137 | + 8 => sprintf(__('CPT submitted. <a target="_blank" href="%s">Preview cpt</a>', 'textdomain'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))), |
|
| 138 | + 9 => sprintf(__('CPT scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview cpt</a>', 'textdomain'), date_i18n(__('M j, Y @ G:i'), strtotime($post->post_date)), esc_url(get_permalink($post_ID))), |
|
| 139 | + 10 => sprintf(__('CPT draft updated. <a target="_blank" href="%s">Preview cpt</a>', 'textdomain'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))), |
|
| 140 | 140 | ); |
| 141 | 141 | |
| 142 | 142 | return $messages; |
@@ -151,17 +151,17 @@ discard block |
||
| 151 | 151 | public function taxonomy_labels() { |
| 152 | 152 | |
| 153 | 153 | $labels = array( |
| 154 | - 'name' => _x( 'Taxonomy', 'taxonomy general name', 'textdomain' ), |
|
| 155 | - 'singular_name' => _x( 'Taxonomy', 'taxonomy singular name', 'textdomain' ), |
|
| 156 | - 'search_items' => __( 'Search Taxonomy', 'textdomain' ), |
|
| 157 | - 'all_items' => __( 'All Taxonomies', 'textdomain' ), |
|
| 158 | - 'parent_item' => __( 'Parent Taxonomy', 'textdomain' ), |
|
| 159 | - 'parent_item_colon' => __( 'Parent Taxonomy:', 'textdomain' ), |
|
| 160 | - 'edit_item' => __( 'Edit Taxonomy', 'textdomain' ), |
|
| 161 | - 'update_item' => __( 'Update Taxonomy', 'textdomain' ), |
|
| 162 | - 'add_new_item' => __( 'Add New Taxonomy', 'textdomain' ), |
|
| 163 | - 'new_item_name' => __( 'New Taxonomy Name', 'textdomain' ), |
|
| 164 | - 'menu_name' => __( 'Taxonomy', 'textdomain' ), |
|
| 154 | + 'name' => _x('Taxonomy', 'taxonomy general name', 'textdomain'), |
|
| 155 | + 'singular_name' => _x('Taxonomy', 'taxonomy singular name', 'textdomain'), |
|
| 156 | + 'search_items' => __('Search Taxonomy', 'textdomain'), |
|
| 157 | + 'all_items' => __('All Taxonomies', 'textdomain'), |
|
| 158 | + 'parent_item' => __('Parent Taxonomy', 'textdomain'), |
|
| 159 | + 'parent_item_colon' => __('Parent Taxonomy:', 'textdomain'), |
|
| 160 | + 'edit_item' => __('Edit Taxonomy', 'textdomain'), |
|
| 161 | + 'update_item' => __('Update Taxonomy', 'textdomain'), |
|
| 162 | + 'add_new_item' => __('Add New Taxonomy', 'textdomain'), |
|
| 163 | + 'new_item_name' => __('New Taxonomy Name', 'textdomain'), |
|
| 164 | + 'menu_name' => __('Taxonomy', 'textdomain'), |
|
| 165 | 165 | ); |
| 166 | 166 | |
| 167 | 167 | return $labels; |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | * |
| 176 | 176 | * @return Array |
| 177 | 177 | */ |
| 178 | - public function taxonomy_args( $labels ) { |
|
| 178 | + public function taxonomy_args($labels) { |
|
| 179 | 179 | |
| 180 | 180 | $args = array( |
| 181 | 181 | 'hierarchical' => true, |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | 'show_ui' => true, |
| 184 | 184 | 'show_admin_column' => true, |
| 185 | 185 | 'query_var' => true, |
| 186 | - 'rewrite' => array( 'slug' => 'custom_tax' ), |
|
| 186 | + 'rewrite' => array('slug' => 'custom_tax'), |
|
| 187 | 187 | 'show_in_rest' => true, |
| 188 | 188 | 'rest_base' => 'custom_tax', |
| 189 | 189 | //Controls WP REST API behaviour |
@@ -1,7 +1,9 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace NirjharLo\WP_Plugin_Framework\Src; |
| 3 | 3 | |
| 4 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 4 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 5 | + exit; |
|
| 6 | +} |
|
| 5 | 7 | |
| 6 | 8 | /** |
| 7 | 9 | * Custom post type class |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace NirjharLo\WP_Plugin_Framework\Src; |
| 3 | 3 | |
| 4 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 4 | +if ( ! defined('ABSPATH')) exit; |
|
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | 7 | * Shortcode class for rendering in front end |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | * @author Nirjhar Lo |
| 10 | 10 | * @package wp-plugin-framework |
| 11 | 11 | */ |
| 12 | -if ( ! class_exists( 'Shortcode' ) ) { |
|
| 12 | +if ( ! class_exists('Shortcode')) { |
|
| 13 | 13 | |
| 14 | 14 | class Shortcode { |
| 15 | 15 | |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | public function __construct() { |
| 22 | 22 | |
| 23 | - add_shortcode( 'shortcode_name', array( $this, 'cb' ) ); |
|
| 23 | + add_shortcode('shortcode_name', array($this, 'cb')); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | /** |
@@ -32,9 +32,9 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | public function cb($atts) { |
| 34 | 34 | |
| 35 | - $data = shortcode_atts( array( |
|
| 35 | + $data = shortcode_atts(array( |
|
| 36 | 36 | 'type' => 'zip', |
| 37 | - ), $atts ); |
|
| 37 | + ), $atts); |
|
| 38 | 38 | |
| 39 | 39 | return $this->html(); |
| 40 | 40 | } |
@@ -1,7 +1,9 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace NirjharLo\WP_Plugin_Framework\Src; |
| 3 | 3 | |
| 4 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
| 4 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 5 | + exit; |
|
| 6 | +} |
|
| 5 | 7 | |
| 6 | 8 | /** |
| 7 | 9 | * Shortcode class for rendering in front end |