@@ -64,12 +64,12 @@ |
||
64 | 64 | |
65 | 65 | |
66 | 66 | /** |
67 | - * Save the Metabox post data |
|
68 | - * |
|
69 | - * @param Array $atts |
|
70 | - * |
|
71 | - * @return Html |
|
72 | - */ |
|
67 | + * Save the Metabox post data |
|
68 | + * |
|
69 | + * @param Array $atts |
|
70 | + * |
|
71 | + * @return Html |
|
72 | + */ |
|
73 | 73 | function save( $post_id, $post ) { |
74 | 74 | |
75 | 75 | //Check if doing autosave |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
2 | +if ( ! defined('ABSPATH')) exit; |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Build a sample metabox in editor screen |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * @author Nirjhar Lo |
8 | 8 | * @package wp-plugin-framework |
9 | 9 | */ |
10 | -if ( ! class_exists( 'PLUGIN_METABOX' ) ) { |
|
10 | +if ( ! class_exists('PLUGIN_METABOX')) { |
|
11 | 11 | |
12 | 12 | final class PLUGIN_METABOX { |
13 | 13 | |
@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | public function __construct() { |
21 | 21 | |
22 | 22 | //Adding the metabox. For custom post type use "add_meta_boxes_posttype" action |
23 | - add_action( 'add_meta_boxes', array( $this, 'register' ) ); |
|
24 | - add_action( 'save_post', array( $this, 'save' ), 10, 2 ); |
|
23 | + add_action('add_meta_boxes', array($this, 'register')); |
|
24 | + add_action('save_post', array($this, 'save'), 10, 2); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | |
@@ -34,8 +34,8 @@ discard block |
||
34 | 34 | |
35 | 35 | add_meta_box( |
36 | 36 | 'meta-box-id', |
37 | - esc_html__( 'MetaBox Title', 'textdomain' ), |
|
38 | - array( $this, 'render' ), |
|
37 | + esc_html__('MetaBox Title', 'textdomain'), |
|
38 | + array($this, 'render'), |
|
39 | 39 | // Declare the post type to show meta box |
40 | 40 | 'post_type', |
41 | 41 | 'normal', |
@@ -51,12 +51,12 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function render() { |
53 | 53 | |
54 | - wp_nonce_field( basename( __FILE__ ), 'metabox_name_nonce' ); ?> |
|
54 | + wp_nonce_field(basename(__FILE__), 'metabox_name_nonce'); ?> |
|
55 | 55 | |
56 | 56 | <p> |
57 | - <label for="metabox_name"><?php _e( "Custom Text", 'textdomain' ); ?></label> |
|
57 | + <label for="metabox_name"><?php _e("Custom Text", 'textdomain'); ?></label> |
|
58 | 58 | <br /> |
59 | - <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 ) ); ?>" /> |
|
59 | + <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)); ?>" /> |
|
60 | 60 | </p> |
61 | 61 | <?php |
62 | 62 | } |
@@ -69,22 +69,22 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return Html |
71 | 71 | */ |
72 | - function save( $post_id, $post ) { |
|
72 | + function save($post_id, $post) { |
|
73 | 73 | |
74 | 74 | //Check if doing autosave |
75 | - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; |
|
75 | + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return; |
|
76 | 76 | |
77 | 77 | //Verify the nonce before proceeding. |
78 | - if ( !isset( $_POST['metabox_name_nonce'] ) || !wp_verify_nonce( $_POST['metabox_name_nonce'], basename( __FILE__ ) ) ) return; |
|
78 | + if ( ! isset($_POST['metabox_name_nonce']) || ! wp_verify_nonce($_POST['metabox_name_nonce'], basename(__FILE__))) return; |
|
79 | 79 | |
80 | 80 | //Get the post type object. |
81 | - $post_type = get_post_type_object( $post->post_type ); |
|
81 | + $post_type = get_post_type_object($post->post_type); |
|
82 | 82 | |
83 | 83 | //Check if the current user has permission to edit the post. |
84 | - if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ) return $post_id; |
|
84 | + if ( ! current_user_can($post_type->cap->edit_post, $post_id)) return $post_id; |
|
85 | 85 | |
86 | - if ( isset( $_POST['metabox_field_name'] ) ) { |
|
87 | - update_post_meta( $post_id, 'metabox_field_name', sanitize_text_field($_POST['metabox_field_name']) ); |
|
86 | + if (isset($_POST['metabox_field_name'])) { |
|
87 | + update_post_meta($post_id, 'metabox_field_name', sanitize_text_field($_POST['metabox_field_name'])); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | } |
@@ -1,5 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
3 | 5 | |
4 | 6 | /** |
5 | 7 | * Build a sample metabox in editor screen |
@@ -73,16 +75,22 @@ discard block |
||
73 | 75 | function save( $post_id, $post ) { |
74 | 76 | |
75 | 77 | //Check if doing autosave |
76 | - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; |
|
78 | + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
|
79 | + return; |
|
80 | + } |
|
77 | 81 | |
78 | 82 | //Verify the nonce before proceeding. |
79 | - if ( !isset( $_POST['metabox_name_nonce'] ) || !wp_verify_nonce( $_POST['metabox_name_nonce'], basename( __FILE__ ) ) ) return; |
|
83 | + if ( !isset( $_POST['metabox_name_nonce'] ) || !wp_verify_nonce( $_POST['metabox_name_nonce'], basename( __FILE__ ) ) ) { |
|
84 | + return; |
|
85 | + } |
|
80 | 86 | |
81 | 87 | //Get the post type object. |
82 | 88 | $post_type = get_post_type_object( $post->post_type ); |
83 | 89 | |
84 | 90 | //Check if the current user has permission to edit the post. |
85 | - if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ) return $post_id; |
|
91 | + if ( !current_user_can( $post_type->cap->edit_post, $post_id ) ) { |
|
92 | + return $post_id; |
|
93 | + } |
|
86 | 94 | |
87 | 95 | if ( isset( $_POST['metabox_field_name'] ) ) { |
88 | 96 | update_post_meta( $post_id, 'metabox_field_name', sanitize_text_field($_POST['metabox_field_name']) ); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
2 | +if ( ! defined('ABSPATH')) exit; |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Implimentation of WordPress inbuilt functions for plugin activation. |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * @author Nirjhar Lo |
8 | 8 | * @package wp-plugin-framework |
9 | 9 | */ |
10 | -if ( ! class_exists( 'PLUGIN_INSTALL' ) ) { |
|
10 | +if ( ! class_exists('PLUGIN_INSTALL')) { |
|
11 | 11 | |
12 | 12 | final class PLUGIN_INSTALL { |
13 | 13 | |
@@ -37,9 +37,9 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function execute() { |
39 | 39 | |
40 | - add_action( 'plugins_loaded', array( $this, 'text_domain_cb' ) ); |
|
41 | - add_action( 'admin_notices', array( $this, 'php_ver_incompatible' ) ); |
|
42 | - add_filter( 'plugin_action_links', array( $this, 'menu_page_link' ), 10, 2 ); |
|
40 | + add_action('plugins_loaded', array($this, 'text_domain_cb')); |
|
41 | + add_action('admin_notices', array($this, 'php_ver_incompatible')); |
|
42 | + add_filter('plugin_action_links', array($this, 'menu_page_link'), 10, 2); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | unload_textdomain($this->text_domain); |
57 | 57 | load_textdomain($this->text_domain, PLUGIN_LN . 'textdomain-' . $locale . '.mo'); |
58 | - load_plugin_textdomain( $this->text_domain, false, PLUGIN_LN ); |
|
58 | + load_plugin_textdomain($this->text_domain, false, PLUGIN_LN); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function php_ver_incompatible() { |
68 | 68 | |
69 | - if ( version_compare( phpversion(), $this->php_ver_allowed, '<' ) ) : |
|
70 | - $text = __( 'The Plugin can\'t be activated because your PHP version', 'textdomain' ); |
|
71 | - $text_last = __( 'is less than required '.$this->php_ver_allowed.'. See more information', 'textdomain' ); |
|
69 | + if (version_compare(phpversion(), $this->php_ver_allowed, '<')) : |
|
70 | + $text = __('The Plugin can\'t be activated because your PHP version', 'textdomain'); |
|
71 | + $text_last = __('is less than required ' . $this->php_ver_allowed . '. See more information', 'textdomain'); |
|
72 | 72 | $text_link = 'php.net/eol.php'; ?> |
73 | 73 | |
74 | 74 | <div id="message" class="updated notice notice-success is-dismissible"> |
@@ -89,20 +89,20 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @return Array |
91 | 91 | */ |
92 | - public function menu_page_link( $links, $file ) { |
|
92 | + public function menu_page_link($links, $file) { |
|
93 | 93 | |
94 | 94 | if ($this->plugin_page_links) { |
95 | 95 | static $this_plugin; |
96 | - if ( ! $this_plugin ) { |
|
96 | + if ( ! $this_plugin) { |
|
97 | 97 | $this_plugin = PLUGIN_FILE; |
98 | 98 | } |
99 | - if ( $file == $this_plugin ) { |
|
99 | + if ($file == $this_plugin) { |
|
100 | 100 | $shift_link = array(); |
101 | 101 | foreach ($this->plugin_page_links as $value) { |
102 | - $shift_link[] = '<a href="'.$value['slug'].'">'.$value['label'].'</a>'; |
|
102 | + $shift_link[] = '<a href="' . $value['slug'] . '">' . $value['label'] . '</a>'; |
|
103 | 103 | } |
104 | - foreach( $shift_link as $val ) { |
|
105 | - array_unshift( $links, $val ); |
|
104 | + foreach ($shift_link as $val) { |
|
105 | + array_unshift($links, $val); |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | return $links; |
@@ -1,5 +1,7 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
3 | 5 | |
4 | 6 | /** |
5 | 7 | * Implimentation of WordPress inbuilt functions for plugin activation. |
@@ -44,13 +44,13 @@ |
||
44 | 44 | global $wpdb; |
45 | 45 | $wpdb->hide_errors(); |
46 | 46 | $collate = ""; |
47 | - if ( $wpdb->has_cap( 'collation' ) ) { |
|
47 | + if ( $wpdb->has_cap( 'collation' ) ) { |
|
48 | 48 | if( ! empty($wpdb->charset ) ) |
49 | 49 | $collate .= "DEFAULT CHARACTER SET $wpdb->charset"; |
50 | 50 | if( ! empty($wpdb->collate ) ) |
51 | 51 | $collate .= " COLLATE $wpdb->collate"; |
52 | - } |
|
53 | - require_once( $this->up_path ); |
|
52 | + } |
|
53 | + require_once( $this->up_path ); |
|
54 | 54 | return $collate; |
55 | 55 | } |
56 | 56 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
2 | +if ( ! defined('ABSPATH')) exit; |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * DB installation class |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * @author Nirjhar Lo |
8 | 8 | * @package wp-plugin-framework |
9 | 9 | */ |
10 | -if ( ! class_exists( 'PLUGIN_DB' ) ) { |
|
10 | +if ( ! class_exists('PLUGIN_DB')) { |
|
11 | 11 | |
12 | 12 | class PLUGIN_DB { |
13 | 13 | |
@@ -44,10 +44,10 @@ discard block |
||
44 | 44 | global $wpdb; |
45 | 45 | $wpdb->hide_errors(); |
46 | 46 | $this->table_name = $wpdb->prefix . $this->table; |
47 | - update_option( '_plugin_db_exist', 0 ); |
|
48 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '$this->table_name'" ) != $this->table_name ) { |
|
49 | - $execute_sql = $this->execute( $this->table_name, $this->collate(), $this->sql ); |
|
50 | - dbDelta( $execute_sql ); |
|
47 | + update_option('_plugin_db_exist', 0); |
|
48 | + if ($wpdb->get_var("SHOW TABLES LIKE '$this->table_name'") != $this->table_name) { |
|
49 | + $execute_sql = $this->execute($this->table_name, $this->collate(), $this->sql); |
|
50 | + dbDelta($execute_sql); |
|
51 | 51 | } |
52 | 52 | } |
53 | 53 | |
@@ -62,13 +62,13 @@ discard block |
||
62 | 62 | global $wpdb; |
63 | 63 | $wpdb->hide_errors(); |
64 | 64 | $collate = ""; |
65 | - if ( $wpdb->has_cap( 'collation' ) ) { |
|
66 | - if( ! empty($wpdb->charset ) ) |
|
65 | + if ($wpdb->has_cap('collation')) { |
|
66 | + if ( ! empty($wpdb->charset)) |
|
67 | 67 | $collate .= "DEFAULT CHARACTER SET $wpdb->charset"; |
68 | - if( ! empty($wpdb->collate ) ) |
|
68 | + if ( ! empty($wpdb->collate)) |
|
69 | 69 | $collate .= " COLLATE $wpdb->collate"; |
70 | 70 | } |
71 | - require_once( $this->up_path ); |
|
71 | + require_once($this->up_path); |
|
72 | 72 | return $collate; |
73 | 73 | } |
74 | 74 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * |
83 | 83 | * @return String |
84 | 84 | */ |
85 | - public function execute( $table_name, $collate, $sql ) { |
|
85 | + public function execute($table_name, $collate, $sql) { |
|
86 | 86 | |
87 | 87 | return "CREATE TABLE $table_name ( $sql ) $collate;"; |
88 | 88 | } |
@@ -98,9 +98,9 @@ discard block |
||
98 | 98 | global $wpdb; |
99 | 99 | |
100 | 100 | $this->table_name = $wpdb->prefix . $this->table; |
101 | - if ( $wpdb->get_var( "SHOW TABLES LIKE '$this->table_name'" ) == $this->table_name ) { |
|
101 | + if ($wpdb->get_var("SHOW TABLES LIKE '$this->table_name'") == $this->table_name) { |
|
102 | 102 | |
103 | - update_option( '_plugin_db_exist', 1 ); |
|
103 | + update_option('_plugin_db_exist', 1); |
|
104 | 104 | } |
105 | 105 | } |
106 | 106 | } |
@@ -1,5 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
3 | 5 | |
4 | 6 | /** |
5 | 7 | * DB installation class |
@@ -45,10 +47,12 @@ discard block |
||
45 | 47 | $wpdb->hide_errors(); |
46 | 48 | $collate = ""; |
47 | 49 | if ( $wpdb->has_cap( 'collation' ) ) { |
48 | - if( ! empty($wpdb->charset ) ) |
|
49 | - $collate .= "DEFAULT CHARACTER SET $wpdb->charset"; |
|
50 | - if( ! empty($wpdb->collate ) ) |
|
51 | - $collate .= " COLLATE $wpdb->collate"; |
|
50 | + if( ! empty($wpdb->charset ) ) { |
|
51 | + $collate .= "DEFAULT CHARACTER SET $wpdb->charset"; |
|
52 | + } |
|
53 | + if( ! empty($wpdb->collate ) ) { |
|
54 | + $collate .= " COLLATE $wpdb->collate"; |
|
55 | + } |
|
52 | 56 | } |
53 | 57 | require_once( $this->up_path ); |
54 | 58 | return $collate; |
@@ -24,11 +24,11 @@ |
||
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Shortcode callback |
27 | - * |
|
28 | - * @param Array $atts |
|
29 | - * |
|
30 | - * @return Html |
|
31 | - */ |
|
27 | + * |
|
28 | + * @param Array $atts |
|
29 | + * |
|
30 | + * @return Html |
|
31 | + */ |
|
32 | 32 | public function cb($atts) { |
33 | 33 | |
34 | 34 | $data = shortcode_atts( array( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
2 | +if ( ! defined('ABSPATH')) exit; |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Shortcode class for rendering in front end |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * @author Nirjhar Lo |
8 | 8 | * @package wp-plugin-framework |
9 | 9 | */ |
10 | -if ( ! class_exists( 'PLUGIN_SHORTCODE' ) ) { |
|
10 | +if ( ! class_exists('PLUGIN_SHORTCODE')) { |
|
11 | 11 | |
12 | 12 | class PLUGIN_SHORTCODE { |
13 | 13 | |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | */ |
19 | 19 | public function __construct() { |
20 | 20 | |
21 | - add_shortcode( 'shortcode_name', array( $this, 'cb' ) ); |
|
21 | + add_shortcode('shortcode_name', array($this, 'cb')); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | /** |
@@ -30,9 +30,9 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function cb($atts) { |
32 | 32 | |
33 | - $data = shortcode_atts( array( |
|
33 | + $data = shortcode_atts(array( |
|
34 | 34 | 'type' => 'zip', |
35 | - ), $atts ); |
|
35 | + ), $atts); |
|
36 | 36 | |
37 | 37 | return $this->html(); |
38 | 38 | } |
@@ -1,5 +1,7 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
3 | 5 | |
4 | 6 | /** |
5 | 7 | * Shortcode class for rendering in front end |
@@ -1,5 +1,7 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
3 | 5 | |
4 | 6 | /** |
5 | 7 | * Custom post type class |
@@ -54,24 +54,24 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function labels() { |
56 | 56 | |
57 | - $labels = array( |
|
58 | - 'name' => _x( '', 'Post Type General Name', 'textdomain' ), |
|
59 | - 'singular_name' => _x( '', 'Post Type Singular Name', 'textdomain' ), |
|
60 | - 'menu_name' => __( '', 'textdomain' ), |
|
61 | - 'parent_item_colon' => __( '', 'textdomain' ), |
|
62 | - 'all_items' => __( '', 'textdomain' ), |
|
63 | - 'view_item' => __( '', 'textdomain' ), |
|
64 | - 'add_new_item' => __( '', 'textdomain' ), |
|
65 | - 'add_new' => __( '', 'textdomain' ), |
|
66 | - 'edit_item' => __( '', 'textdomain' ), |
|
67 | - 'update_item' => __( '', 'textdomain' ), |
|
68 | - 'search_items' => __( '', 'textdomain' ), |
|
69 | - 'not_found' => __( '', 'textdomain' ), |
|
70 | - 'not_found_in_trash' => __( '', 'textdomain' ), |
|
71 | - ); |
|
72 | - |
|
73 | - return $labels; |
|
74 | - } |
|
57 | + $labels = array( |
|
58 | + 'name' => _x( '', 'Post Type General Name', 'textdomain' ), |
|
59 | + 'singular_name' => _x( '', 'Post Type Singular Name', 'textdomain' ), |
|
60 | + 'menu_name' => __( '', 'textdomain' ), |
|
61 | + 'parent_item_colon' => __( '', 'textdomain' ), |
|
62 | + 'all_items' => __( '', 'textdomain' ), |
|
63 | + 'view_item' => __( '', 'textdomain' ), |
|
64 | + 'add_new_item' => __( '', 'textdomain' ), |
|
65 | + 'add_new' => __( '', 'textdomain' ), |
|
66 | + 'edit_item' => __( '', 'textdomain' ), |
|
67 | + 'update_item' => __( '', 'textdomain' ), |
|
68 | + 'search_items' => __( '', 'textdomain' ), |
|
69 | + 'not_found' => __( '', 'textdomain' ), |
|
70 | + 'not_found_in_trash' => __( '', 'textdomain' ), |
|
71 | + ); |
|
72 | + |
|
73 | + return $labels; |
|
74 | + } |
|
75 | 75 | |
76 | 76 | |
77 | 77 | /** |
@@ -81,44 +81,44 @@ discard block |
||
81 | 81 | * |
82 | 82 | * @return Array |
83 | 83 | */ |
84 | - public function args( $labels ) { |
|
85 | - |
|
86 | - $args = array( |
|
87 | - 'label' => __( '', 'textdomain' ), |
|
88 | - 'description' => __( '', 'textdomain' ), |
|
89 | - 'labels' => $labels, |
|
90 | - 'supports' => array( 'title', 'editor', 'thumbnail' ), |
|
91 | - 'taxonomies' => array( 'custom_tax', 'post_tag' ), |
|
92 | - 'hierarchical' => true, |
|
93 | - 'public' => true, |
|
84 | + public function args( $labels ) { |
|
85 | + |
|
86 | + $args = array( |
|
87 | + 'label' => __( '', 'textdomain' ), |
|
88 | + 'description' => __( '', 'textdomain' ), |
|
89 | + 'labels' => $labels, |
|
90 | + 'supports' => array( 'title', 'editor', 'thumbnail' ), |
|
91 | + 'taxonomies' => array( 'custom_tax', 'post_tag' ), |
|
92 | + 'hierarchical' => true, |
|
93 | + 'public' => true, |
|
94 | 94 | 'rewrite' => array( 'slug' => 'slug_name' ), |
95 | - 'show_ui' => true, |
|
96 | - 'show_in_menu' => true, |
|
95 | + 'show_ui' => true, |
|
96 | + 'show_in_menu' => true, |
|
97 | 97 | 'menu_icon' => 'data:image/svg+xml;base64,' . self::$menu_svg, |
98 | - 'show_in_nav_menus' => true, |
|
99 | - 'show_in_admin_bar' => true, |
|
100 | - 'menu_position' => 5, |
|
101 | - 'can_export' => true, |
|
102 | - 'has_archive' => true, |
|
103 | - 'exclude_from_search' => false, |
|
104 | - 'publicly_queryable' => true, |
|
105 | - 'capability_type' => 'post', |
|
106 | - 'show_in_rest' => true, |
|
98 | + 'show_in_nav_menus' => true, |
|
99 | + 'show_in_admin_bar' => true, |
|
100 | + 'menu_position' => 5, |
|
101 | + 'can_export' => true, |
|
102 | + 'has_archive' => true, |
|
103 | + 'exclude_from_search' => false, |
|
104 | + 'publicly_queryable' => true, |
|
105 | + 'capability_type' => 'post', |
|
106 | + 'show_in_rest' => true, |
|
107 | 107 | //Controls WP REST API behaviour |
108 | 108 | 'rest_controller_class' => 'WP_REST_Posts_Controller', |
109 | - ); |
|
109 | + ); |
|
110 | 110 | |
111 | - return $args; |
|
112 | - } |
|
111 | + return $args; |
|
112 | + } |
|
113 | 113 | |
114 | 114 | |
115 | 115 | /** |
116 | - * Modify the cpt messages |
|
116 | + * Modify the cpt messages |
|
117 | 117 | * |
118 | 118 | * @param Array $messages |
119 | 119 | * |
120 | 120 | * @return Array |
121 | - */ |
|
121 | + */ |
|
122 | 122 | public function cpt_updated_messages( $messages ) { |
123 | 123 | |
124 | 124 | global $post, $post_ID; |
@@ -142,24 +142,24 @@ discard block |
||
142 | 142 | |
143 | 143 | |
144 | 144 | /** |
145 | - * Taxonomy labels |
|
146 | - * |
|
147 | - * @return Array |
|
148 | - */ |
|
145 | + * Taxonomy labels |
|
146 | + * |
|
147 | + * @return Array |
|
148 | + */ |
|
149 | 149 | public function taxonomy_labels() { |
150 | 150 | |
151 | 151 | $labels = array( |
152 | - 'name' => _x( 'Taxonomy', 'taxonomy general name', 'textdomain' ), |
|
153 | - 'singular_name' => _x( 'Taxonomy', 'taxonomy singular name', 'textdomain' ), |
|
154 | - 'search_items' => __( 'Search Taxonomy', 'textdomain' ), |
|
155 | - 'all_items' => __( 'All Taxonomies', 'textdomain' ), |
|
156 | - 'parent_item' => __( 'Parent Taxonomy', 'textdomain' ), |
|
157 | - 'parent_item_colon' => __( 'Parent Taxonomy:', 'textdomain' ), |
|
158 | - 'edit_item' => __( 'Edit Taxonomy', 'textdomain' ), |
|
159 | - 'update_item' => __( 'Update Taxonomy', 'textdomain' ), |
|
160 | - 'add_new_item' => __( 'Add New Taxonomy', 'textdomain' ), |
|
161 | - 'new_item_name' => __( 'New Taxonomy Name', 'textdomain' ), |
|
162 | - 'menu_name' => __( 'Taxonomy', 'textdomain' ), |
|
152 | + 'name' => _x( 'Taxonomy', 'taxonomy general name', 'textdomain' ), |
|
153 | + 'singular_name' => _x( 'Taxonomy', 'taxonomy singular name', 'textdomain' ), |
|
154 | + 'search_items' => __( 'Search Taxonomy', 'textdomain' ), |
|
155 | + 'all_items' => __( 'All Taxonomies', 'textdomain' ), |
|
156 | + 'parent_item' => __( 'Parent Taxonomy', 'textdomain' ), |
|
157 | + 'parent_item_colon' => __( 'Parent Taxonomy:', 'textdomain' ), |
|
158 | + 'edit_item' => __( 'Edit Taxonomy', 'textdomain' ), |
|
159 | + 'update_item' => __( 'Update Taxonomy', 'textdomain' ), |
|
160 | + 'add_new_item' => __( 'Add New Taxonomy', 'textdomain' ), |
|
161 | + 'new_item_name' => __( 'New Taxonomy Name', 'textdomain' ), |
|
162 | + 'menu_name' => __( 'Taxonomy', 'textdomain' ), |
|
163 | 163 | ); |
164 | 164 | |
165 | 165 | return $labels; |
@@ -167,28 +167,28 @@ discard block |
||
167 | 167 | |
168 | 168 | |
169 | 169 | /** |
170 | - * Define the arguments for custom taxonomy |
|
171 | - * |
|
172 | - * @param Array $labels |
|
173 | - * |
|
174 | - * @return Array |
|
175 | - */ |
|
176 | - public function taxonomy_args( $labels ) { |
|
177 | - |
|
178 | - $args = array( |
|
170 | + * Define the arguments for custom taxonomy |
|
171 | + * |
|
172 | + * @param Array $labels |
|
173 | + * |
|
174 | + * @return Array |
|
175 | + */ |
|
176 | + public function taxonomy_args( $labels ) { |
|
177 | + |
|
178 | + $args = array( |
|
179 | 179 | 'hierarchical' => true, |
180 | - 'labels' => $labels, |
|
181 | - 'show_ui' => true, |
|
182 | - 'show_admin_column' => true, |
|
183 | - 'query_var' => true, |
|
184 | - 'rewrite' => array( 'slug' => 'custom_tax' ), |
|
185 | - 'show_in_rest' => true, |
|
186 | - 'rest_base' => 'custom_tax', |
|
180 | + 'labels' => $labels, |
|
181 | + 'show_ui' => true, |
|
182 | + 'show_admin_column' => true, |
|
183 | + 'query_var' => true, |
|
184 | + 'rewrite' => array( 'slug' => 'custom_tax' ), |
|
185 | + 'show_in_rest' => true, |
|
186 | + 'rest_base' => 'custom_tax', |
|
187 | 187 | //Controls WP REST API behaviour |
188 | - 'rest_controller_class' => 'WP_REST_Terms_Controller', |
|
189 | - ); |
|
188 | + 'rest_controller_class' => 'WP_REST_Terms_Controller', |
|
189 | + ); |
|
190 | 190 | |
191 | - return $args; |
|
192 | - } |
|
191 | + return $args; |
|
192 | + } |
|
193 | 193 | } |
194 | 194 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
2 | +if ( ! defined('ABSPATH')) exit; |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Custom post type class |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * @author Nirjhar Lo |
8 | 8 | * @package wp-plugin-framework |
9 | 9 | */ |
10 | -if ( ! class_exists( 'PLUGIN_CPT' ) ) { |
|
10 | +if ( ! class_exists('PLUGIN_CPT')) { |
|
11 | 11 | |
12 | 12 | class PLUGIN_CPT { |
13 | 13 | |
@@ -35,10 +35,10 @@ discard block |
||
35 | 35 | public function __construct() { |
36 | 36 | |
37 | 37 | $this->labels = $this->labels(); |
38 | - $this->args = $this->args( $this->labels ); |
|
38 | + $this->args = $this->args($this->labels); |
|
39 | 39 | |
40 | 40 | $this->taxonomy_labels = $this->taxonomy_labels(); |
41 | - $this->taxonomy_args = $this->taxonomy_args( $this->taxonomy_labels ); |
|
41 | + $this->taxonomy_args = $this->taxonomy_args($this->taxonomy_labels); |
|
42 | 42 | |
43 | 43 | //register_post_type( 'cpt_name', $this->args ); |
44 | 44 | //add_filter( 'post_updated_messages', array( $this, 'group_updated_messages' ) ); |
@@ -55,19 +55,19 @@ discard block |
||
55 | 55 | public function labels() { |
56 | 56 | |
57 | 57 | $labels = array( |
58 | - 'name' => _x( '', 'Post Type General Name', 'textdomain' ), |
|
59 | - 'singular_name' => _x( '', 'Post Type Singular Name', 'textdomain' ), |
|
60 | - 'menu_name' => __( '', 'textdomain' ), |
|
61 | - 'parent_item_colon' => __( '', 'textdomain' ), |
|
62 | - 'all_items' => __( '', 'textdomain' ), |
|
63 | - 'view_item' => __( '', 'textdomain' ), |
|
64 | - 'add_new_item' => __( '', 'textdomain' ), |
|
65 | - 'add_new' => __( '', 'textdomain' ), |
|
66 | - 'edit_item' => __( '', 'textdomain' ), |
|
67 | - 'update_item' => __( '', 'textdomain' ), |
|
68 | - 'search_items' => __( '', 'textdomain' ), |
|
69 | - 'not_found' => __( '', 'textdomain' ), |
|
70 | - 'not_found_in_trash' => __( '', 'textdomain' ), |
|
58 | + 'name' => _x('', 'Post Type General Name', 'textdomain'), |
|
59 | + 'singular_name' => _x('', 'Post Type Singular Name', 'textdomain'), |
|
60 | + 'menu_name' => __('', 'textdomain'), |
|
61 | + 'parent_item_colon' => __('', 'textdomain'), |
|
62 | + 'all_items' => __('', 'textdomain'), |
|
63 | + 'view_item' => __('', 'textdomain'), |
|
64 | + 'add_new_item' => __('', 'textdomain'), |
|
65 | + 'add_new' => __('', 'textdomain'), |
|
66 | + 'edit_item' => __('', 'textdomain'), |
|
67 | + 'update_item' => __('', 'textdomain'), |
|
68 | + 'search_items' => __('', 'textdomain'), |
|
69 | + 'not_found' => __('', 'textdomain'), |
|
70 | + 'not_found_in_trash' => __('', 'textdomain'), |
|
71 | 71 | ); |
72 | 72 | |
73 | 73 | return $labels; |
@@ -81,17 +81,17 @@ discard block |
||
81 | 81 | * |
82 | 82 | * @return Array |
83 | 83 | */ |
84 | - public function args( $labels ) { |
|
84 | + public function args($labels) { |
|
85 | 85 | |
86 | 86 | $args = array( |
87 | - 'label' => __( '', 'textdomain' ), |
|
88 | - 'description' => __( '', 'textdomain' ), |
|
87 | + 'label' => __('', 'textdomain'), |
|
88 | + 'description' => __('', 'textdomain'), |
|
89 | 89 | 'labels' => $labels, |
90 | - 'supports' => array( 'title', 'editor', 'thumbnail' ), |
|
91 | - 'taxonomies' => array( 'custom_tax', 'post_tag' ), |
|
90 | + 'supports' => array('title', 'editor', 'thumbnail'), |
|
91 | + 'taxonomies' => array('custom_tax', 'post_tag'), |
|
92 | 92 | 'hierarchical' => true, |
93 | 93 | 'public' => true, |
94 | - 'rewrite' => array( 'slug' => 'slug_name' ), |
|
94 | + 'rewrite' => array('slug' => 'slug_name'), |
|
95 | 95 | 'show_ui' => true, |
96 | 96 | 'show_in_menu' => true, |
97 | 97 | 'menu_icon' => 'data:image/svg+xml;base64,' . self::$menu_svg, |
@@ -119,22 +119,22 @@ discard block |
||
119 | 119 | * |
120 | 120 | * @return Array |
121 | 121 | */ |
122 | - public function cpt_updated_messages( $messages ) { |
|
122 | + public function cpt_updated_messages($messages) { |
|
123 | 123 | |
124 | 124 | global $post, $post_ID; |
125 | 125 | |
126 | 126 | $messages['cpt_name'] = array( |
127 | 127 | 0 => '', |
128 | - 1 => sprintf( __( 'CPT updated. <a href="%s">View CPT</a>', 'textdomain' ), esc_url( get_permalink( $post_ID ) ) ), |
|
129 | - 2 => __( 'field updated.', 'textdomain' ), |
|
130 | - 3 => __( 'field deleted.', 'textdomain' ), |
|
131 | - 4 => __( 'CPT updated.', 'textdomain' ), |
|
132 | - 5 => ( isset( $_GET['revision'] ) ? sprintf( __( 'CPT restored to revision from %s', 'textdomain' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false ), |
|
133 | - 6 => sprintf( __( 'CPT published. <a href="%s">View Cpt</a>', 'textdomain' ), esc_url( get_permalink( $post_ID ) ) ), |
|
134 | - 7 => __( 'CPT saved.', 'textdomain' ), |
|
135 | - 8 => sprintf( __( 'CPT submitted. <a target="_blank" href="%s">Preview cpt</a>', 'textdomain' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ), |
|
136 | - 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 ) ) ), |
|
137 | - 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 ) ) ) ), |
|
128 | + 1 => sprintf(__('CPT updated. <a href="%s">View CPT</a>', 'textdomain'), esc_url(get_permalink($post_ID))), |
|
129 | + 2 => __('field updated.', 'textdomain'), |
|
130 | + 3 => __('field deleted.', 'textdomain'), |
|
131 | + 4 => __('CPT updated.', 'textdomain'), |
|
132 | + 5 => (isset($_GET['revision']) ? sprintf(__('CPT restored to revision from %s', 'textdomain'), wp_post_revision_title((int) $_GET['revision'], false)) : false), |
|
133 | + 6 => sprintf(__('CPT published. <a href="%s">View Cpt</a>', 'textdomain'), esc_url(get_permalink($post_ID))), |
|
134 | + 7 => __('CPT saved.', 'textdomain'), |
|
135 | + 8 => sprintf(__('CPT submitted. <a target="_blank" href="%s">Preview cpt</a>', 'textdomain'), esc_url(add_query_arg('preview', 'true', get_permalink($post_ID)))), |
|
136 | + 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))), |
|
137 | + 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)))), |
|
138 | 138 | ); |
139 | 139 | |
140 | 140 | return $messages; |
@@ -149,17 +149,17 @@ discard block |
||
149 | 149 | public function taxonomy_labels() { |
150 | 150 | |
151 | 151 | $labels = array( |
152 | - 'name' => _x( 'Taxonomy', 'taxonomy general name', 'textdomain' ), |
|
153 | - 'singular_name' => _x( 'Taxonomy', 'taxonomy singular name', 'textdomain' ), |
|
154 | - 'search_items' => __( 'Search Taxonomy', 'textdomain' ), |
|
155 | - 'all_items' => __( 'All Taxonomies', 'textdomain' ), |
|
156 | - 'parent_item' => __( 'Parent Taxonomy', 'textdomain' ), |
|
157 | - 'parent_item_colon' => __( 'Parent Taxonomy:', 'textdomain' ), |
|
158 | - 'edit_item' => __( 'Edit Taxonomy', 'textdomain' ), |
|
159 | - 'update_item' => __( 'Update Taxonomy', 'textdomain' ), |
|
160 | - 'add_new_item' => __( 'Add New Taxonomy', 'textdomain' ), |
|
161 | - 'new_item_name' => __( 'New Taxonomy Name', 'textdomain' ), |
|
162 | - 'menu_name' => __( 'Taxonomy', 'textdomain' ), |
|
152 | + 'name' => _x('Taxonomy', 'taxonomy general name', 'textdomain'), |
|
153 | + 'singular_name' => _x('Taxonomy', 'taxonomy singular name', 'textdomain'), |
|
154 | + 'search_items' => __('Search Taxonomy', 'textdomain'), |
|
155 | + 'all_items' => __('All Taxonomies', 'textdomain'), |
|
156 | + 'parent_item' => __('Parent Taxonomy', 'textdomain'), |
|
157 | + 'parent_item_colon' => __('Parent Taxonomy:', 'textdomain'), |
|
158 | + 'edit_item' => __('Edit Taxonomy', 'textdomain'), |
|
159 | + 'update_item' => __('Update Taxonomy', 'textdomain'), |
|
160 | + 'add_new_item' => __('Add New Taxonomy', 'textdomain'), |
|
161 | + 'new_item_name' => __('New Taxonomy Name', 'textdomain'), |
|
162 | + 'menu_name' => __('Taxonomy', 'textdomain'), |
|
163 | 163 | ); |
164 | 164 | |
165 | 165 | return $labels; |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | * |
174 | 174 | * @return Array |
175 | 175 | */ |
176 | - public function taxonomy_args( $labels ) { |
|
176 | + public function taxonomy_args($labels) { |
|
177 | 177 | |
178 | 178 | $args = array( |
179 | 179 | 'hierarchical' => true, |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | 'show_ui' => true, |
182 | 182 | 'show_admin_column' => true, |
183 | 183 | 'query_var' => true, |
184 | - 'rewrite' => array( 'slug' => 'custom_tax' ), |
|
184 | + 'rewrite' => array('slug' => 'custom_tax'), |
|
185 | 185 | 'show_in_rest' => true, |
186 | 186 | 'rest_base' => 'custom_tax', |
187 | 187 | //Controls WP REST API behaviour |
@@ -1,5 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
3 | 5 | |
4 | 6 | /** |
5 | 7 | * Main plugin object to define the plugin |
@@ -95,7 +97,9 @@ discard block |
||
95 | 97 | } |
96 | 98 | |
97 | 99 | //If CPT exists, include taht and flush the rewrite rules |
98 | - if ( class_exists( 'PLUGIN_CPT' ) ) new PLUGIN_CPT(); |
|
100 | + if ( class_exists( 'PLUGIN_CPT' ) ) { |
|
101 | + new PLUGIN_CPT(); |
|
102 | + } |
|
99 | 103 | flush_rewrite_rules(); |
100 | 104 | } |
101 | 105 | |
@@ -228,7 +232,9 @@ discard block |
||
228 | 232 | */ |
229 | 233 | public function cpt() { |
230 | 234 | |
231 | - if ( class_exists( 'PLUGIN_CPT' ) ) new PLUGIN_CPT(); |
|
235 | + if ( class_exists( 'PLUGIN_CPT' ) ) { |
|
236 | + new PLUGIN_CPT(); |
|
237 | + } |
|
232 | 238 | } |
233 | 239 | |
234 | 240 | |
@@ -239,7 +245,9 @@ discard block |
||
239 | 245 | */ |
240 | 246 | public function scripts() { |
241 | 247 | |
242 | - if ( class_exists( 'PLUGIN_SCRIPT' ) ) new PLUGIN_SCRIPT(); |
|
248 | + if ( class_exists( 'PLUGIN_SCRIPT' ) ) { |
|
249 | + new PLUGIN_SCRIPT(); |
|
250 | + } |
|
243 | 251 | } |
244 | 252 | |
245 | 253 | |
@@ -250,7 +258,9 @@ discard block |
||
250 | 258 | */ |
251 | 259 | public function settings() { |
252 | 260 | |
253 | - if ( class_exists( 'PLUGIN_SETTINGS' ) ) new PLUGIN_SETTINGS(); |
|
261 | + if ( class_exists( 'PLUGIN_SETTINGS' ) ) { |
|
262 | + new PLUGIN_SETTINGS(); |
|
263 | + } |
|
254 | 264 | } |
255 | 265 | |
256 | 266 | |
@@ -261,7 +271,9 @@ discard block |
||
261 | 271 | */ |
262 | 272 | public function widgets() { |
263 | 273 | |
264 | - if ( class_exists( 'PLUGIN_WIDGET' ) ) new PLUGIN_WIDGET(); |
|
274 | + if ( class_exists( 'PLUGIN_WIDGET' ) ) { |
|
275 | + new PLUGIN_WIDGET(); |
|
276 | + } |
|
265 | 277 | } |
266 | 278 | |
267 | 279 | |
@@ -272,7 +284,9 @@ discard block |
||
272 | 284 | */ |
273 | 285 | public function metabox() { |
274 | 286 | |
275 | - if ( class_exists( 'PLUGIN_METABOX' ) ) new PLUGIN_METABOX(); |
|
287 | + if ( class_exists( 'PLUGIN_METABOX' ) ) { |
|
288 | + new PLUGIN_METABOX(); |
|
289 | + } |
|
276 | 290 | } |
277 | 291 | |
278 | 292 | |
@@ -283,7 +297,9 @@ discard block |
||
283 | 297 | */ |
284 | 298 | public function shortcode() { |
285 | 299 | |
286 | - if ( class_exists( 'PLUGIN_SHORTCODE' ) ) new PLUGIN_SHORTCODE(); |
|
300 | + if ( class_exists( 'PLUGIN_SHORTCODE' ) ) { |
|
301 | + new PLUGIN_SHORTCODE(); |
|
302 | + } |
|
287 | 303 | } |
288 | 304 | |
289 | 305 | |
@@ -294,7 +310,9 @@ discard block |
||
294 | 310 | */ |
295 | 311 | public function rest_api() { |
296 | 312 | |
297 | - if ( class_exists( 'PLUGIN_CUSTOM_ROUTE' ) ) new PLUGIN_CUSTOM_ROUTE(); |
|
313 | + if ( class_exists( 'PLUGIN_CUSTOM_ROUTE' ) ) { |
|
314 | + new PLUGIN_CUSTOM_ROUTE(); |
|
315 | + } |
|
298 | 316 | } |
299 | 317 | |
300 | 318 |
@@ -299,28 +299,28 @@ |
||
299 | 299 | |
300 | 300 | |
301 | 301 | /** |
302 | - * Instantiate REST API |
|
303 | - * |
|
304 | - * @return Void |
|
305 | - */ |
|
302 | + * Instantiate REST API |
|
303 | + * |
|
304 | + * @return Void |
|
305 | + */ |
|
306 | 306 | public function prevent_unauthorized_rest_access( $result ) { |
307 | - // If a previous authentication check was applied, |
|
308 | - // pass that result along without modification. |
|
309 | - if ( true === $result || is_wp_error( $result ) ) { |
|
310 | - return $result; |
|
311 | - } |
|
312 | - |
|
313 | - // No authentication has been performed yet. |
|
314 | - // Return an error if user is not logged in. |
|
315 | - if ( ! is_user_logged_in() ) { |
|
316 | - return new WP_Error( |
|
317 | - 'rest_not_logged_in', |
|
318 | - __( 'You are not currently logged in.' ), |
|
319 | - array( 'status' => 401 ) |
|
320 | - ); |
|
321 | - } |
|
322 | - |
|
323 | - return $result; |
|
307 | + // If a previous authentication check was applied, |
|
308 | + // pass that result along without modification. |
|
309 | + if ( true === $result || is_wp_error( $result ) ) { |
|
310 | + return $result; |
|
311 | + } |
|
312 | + |
|
313 | + // No authentication has been performed yet. |
|
314 | + // Return an error if user is not logged in. |
|
315 | + if ( ! is_user_logged_in() ) { |
|
316 | + return new WP_Error( |
|
317 | + 'rest_not_logged_in', |
|
318 | + __( 'You are not currently logged in.' ), |
|
319 | + array( 'status' => 401 ) |
|
320 | + ); |
|
321 | + } |
|
322 | + |
|
323 | + return $result; |
|
324 | 324 | } |
325 | 325 | |
326 | 326 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
2 | +if ( ! defined('ABSPATH')) exit; |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Main plugin object to define the plugin |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @author Nirjhar Lo |
9 | 9 | * @package wp-plugin-framework |
10 | 10 | */ |
11 | -if ( ! class_exists( 'PLUGIN_BUILD' ) ) { |
|
11 | +if ( ! class_exists('PLUGIN_BUILD')) { |
|
12 | 12 | |
13 | 13 | final class PLUGIN_BUILD { |
14 | 14 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public static function instance() { |
71 | 71 | |
72 | - if ( is_null( self::$_instance ) ) { |
|
72 | + if (is_null(self::$_instance)) { |
|
73 | 73 | self::$_instance = new self(); |
74 | 74 | self::$_instance->init(); |
75 | 75 | } |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | } |
96 | 96 | |
97 | 97 | //If CPT exists, include taht and flush the rewrite rules |
98 | - if ( class_exists( 'PLUGIN_CPT' ) ) new PLUGIN_CPT(); |
|
98 | + if (class_exists('PLUGIN_CPT')) new PLUGIN_CPT(); |
|
99 | 99 | flush_rewrite_rules(); |
100 | 100 | } |
101 | 101 | |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | */ |
108 | 108 | public function cron_activation() { |
109 | 109 | |
110 | - if ( class_exists( 'PLUGIN_CRON' ) ) { |
|
110 | + if (class_exists('PLUGIN_CRON')) { |
|
111 | 111 | |
112 | 112 | $cron = new PLUGIN_CRON(); |
113 | 113 | $schedule = $cron->schedule_task( |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function db_install() { |
132 | 132 | |
133 | - if ( class_exists( 'PLUGIN_DB' ) ) { |
|
133 | + if (class_exists('PLUGIN_DB')) { |
|
134 | 134 | |
135 | 135 | $db = new PLUGIN_DB(); |
136 | 136 | $db->table = self::$plugin_table; |
@@ -140,15 +140,15 @@ discard block |
||
140 | 140 | $db->build(); |
141 | 141 | } |
142 | 142 | |
143 | - if (get_option( '_plugin_db_exist') == '0' ) { |
|
144 | - add_action( 'admin_notices', array( $this, 'db_error_msg' ) ); |
|
143 | + if (get_option('_plugin_db_exist') == '0') { |
|
144 | + add_action('admin_notices', array($this, 'db_error_msg')); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | $options = array( |
148 | - array( 'option_name', '__value__' ), |
|
148 | + array('option_name', '__value__'), |
|
149 | 149 | ); |
150 | - foreach ( $options as $value ) { |
|
151 | - update_option( $value[0], $value[1] ); |
|
150 | + foreach ($options as $value) { |
|
151 | + update_option($value[0], $value[1]); |
|
152 | 152 | } |
153 | 153 | } |
154 | 154 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | public function db_error_msg() { ?> |
162 | 162 | |
163 | 163 | <div class="notice notice-error is-dismissible"> |
164 | - <p><?php _e( 'Database table Not installed correctly.', 'textdomain' ); ?></p> |
|
164 | + <p><?php _e('Database table Not installed correctly.', 'textdomain'); ?></p> |
|
165 | 165 | </div> |
166 | 166 | <?php |
167 | 167 | } |
@@ -177,13 +177,13 @@ discard block |
||
177 | 177 | $table_name = self::$plugin_table; |
178 | 178 | |
179 | 179 | global $wpdb; |
180 | - $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}$table_name" ); |
|
180 | + $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}$table_name"); |
|
181 | 181 | |
182 | 182 | $options = array( |
183 | 183 | '_plugin_db_exist' |
184 | 184 | ); |
185 | - foreach ( $options as $value ) { |
|
186 | - delete_option( $value ); |
|
185 | + foreach ($options as $value) { |
|
186 | + delete_option($value); |
|
187 | 187 | } |
188 | 188 | } |
189 | 189 | |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | */ |
207 | 207 | public function custom_cron_hook_cb() { |
208 | 208 | |
209 | - add_action( 'custom_cron_hook', array( $this, 'do_cron_job_function' ) ); |
|
209 | + add_action('custom_cron_hook', array($this, 'do_cron_job_function')); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | */ |
218 | 218 | public function cron_uninstall() { |
219 | 219 | |
220 | - wp_clear_scheduled_hook( 'custom_cron_hook' ); |
|
220 | + wp_clear_scheduled_hook('custom_cron_hook'); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | */ |
229 | 229 | public function cpt() { |
230 | 230 | |
231 | - if ( class_exists( 'PLUGIN_CPT' ) ) new PLUGIN_CPT(); |
|
231 | + if (class_exists('PLUGIN_CPT')) new PLUGIN_CPT(); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | */ |
240 | 240 | public function scripts() { |
241 | 241 | |
242 | - if ( class_exists( 'PLUGIN_SCRIPT' ) ) new PLUGIN_SCRIPT(); |
|
242 | + if (class_exists('PLUGIN_SCRIPT')) new PLUGIN_SCRIPT(); |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | */ |
251 | 251 | public function settings() { |
252 | 252 | |
253 | - if ( class_exists( 'PLUGIN_SETTINGS' ) ) new PLUGIN_SETTINGS(); |
|
253 | + if (class_exists('PLUGIN_SETTINGS')) new PLUGIN_SETTINGS(); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | */ |
262 | 262 | public function widgets() { |
263 | 263 | |
264 | - if ( class_exists( 'PLUGIN_WIDGET' ) ) new PLUGIN_WIDGET(); |
|
264 | + if (class_exists('PLUGIN_WIDGET')) new PLUGIN_WIDGET(); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | */ |
273 | 273 | public function metabox() { |
274 | 274 | |
275 | - if ( class_exists( 'PLUGIN_METABOX' ) ) new PLUGIN_METABOX(); |
|
275 | + if (class_exists('PLUGIN_METABOX')) new PLUGIN_METABOX(); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | */ |
284 | 284 | public function shortcode() { |
285 | 285 | |
286 | - if ( class_exists( 'PLUGIN_SHORTCODE' ) ) new PLUGIN_SHORTCODE(); |
|
286 | + if (class_exists('PLUGIN_SHORTCODE')) new PLUGIN_SHORTCODE(); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | */ |
295 | 295 | public function rest_api() { |
296 | 296 | |
297 | - if ( class_exists( 'PLUGIN_CUSTOM_ROUTE' ) ) new PLUGIN_CUSTOM_ROUTE(); |
|
297 | + if (class_exists('PLUGIN_CUSTOM_ROUTE')) new PLUGIN_CUSTOM_ROUTE(); |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | |
@@ -303,20 +303,20 @@ discard block |
||
303 | 303 | * |
304 | 304 | * @return Void |
305 | 305 | */ |
306 | - public function prevent_unauthorized_rest_access( $result ) { |
|
306 | + public function prevent_unauthorized_rest_access($result) { |
|
307 | 307 | // If a previous authentication check was applied, |
308 | 308 | // pass that result along without modification. |
309 | - if ( true === $result || is_wp_error( $result ) ) { |
|
309 | + if (true === $result || is_wp_error($result)) { |
|
310 | 310 | return $result; |
311 | 311 | } |
312 | 312 | |
313 | 313 | // No authentication has been performed yet. |
314 | 314 | // Return an error if user is not logged in. |
315 | - if ( ! is_user_logged_in() ) { |
|
315 | + if ( ! is_user_logged_in()) { |
|
316 | 316 | return new WP_Error( |
317 | 317 | 'rest_not_logged_in', |
318 | - __( 'You are not currently logged in.' ), |
|
319 | - array( 'status' => 401 ) |
|
318 | + __('You are not currently logged in.'), |
|
319 | + array('status' => 401) |
|
320 | 320 | ); |
321 | 321 | } |
322 | 322 | |
@@ -332,15 +332,15 @@ discard block |
||
332 | 332 | */ |
333 | 333 | public function functionality() { |
334 | 334 | |
335 | - require_once( 'src/class-install.php' ); |
|
336 | - require_once( 'src/class-db.php' ); |
|
337 | - require_once( 'src/class-query.php' ); |
|
338 | - require_once( 'src/class-settings.php' ); |
|
339 | - require_once( 'src/class-widget.php' ); |
|
340 | - require_once( 'src/class-metabox.php' ); |
|
341 | - require_once( 'src/class-shortcode.php' ); |
|
342 | - require_once( 'src/class-cpt.php' ); |
|
343 | - require_once( 'src/class-rest.php' ); |
|
335 | + require_once('src/class-install.php'); |
|
336 | + require_once('src/class-db.php'); |
|
337 | + require_once('src/class-query.php'); |
|
338 | + require_once('src/class-settings.php'); |
|
339 | + require_once('src/class-widget.php'); |
|
340 | + require_once('src/class-metabox.php'); |
|
341 | + require_once('src/class-shortcode.php'); |
|
342 | + require_once('src/class-cpt.php'); |
|
343 | + require_once('src/class-rest.php'); |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | |
@@ -352,12 +352,12 @@ discard block |
||
352 | 352 | */ |
353 | 353 | public function helpers() { |
354 | 354 | |
355 | - require_once( 'lib/class-cron.php' ); |
|
356 | - require_once( 'lib/class-api.php' ); |
|
357 | - require_once( 'lib/class-table.php' ); |
|
358 | - require_once( 'lib/class-ajax.php' ); |
|
359 | - require_once( 'lib/class-upload.php' ); |
|
360 | - require_once( 'lib/class-script.php' ); |
|
355 | + require_once('lib/class-cron.php'); |
|
356 | + require_once('lib/class-api.php'); |
|
357 | + require_once('lib/class-table.php'); |
|
358 | + require_once('lib/class-ajax.php'); |
|
359 | + require_once('lib/class-upload.php'); |
|
360 | + require_once('lib/class-script.php'); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | |
@@ -371,19 +371,19 @@ discard block |
||
371 | 371 | $this->helpers(); |
372 | 372 | $this->functionality(); |
373 | 373 | |
374 | - register_activation_hook( PLUGIN_FILE, array( $this, 'db_install' ) ); |
|
375 | - register_activation_hook( PLUGIN_FILE, array( $this, 'cron_activation' ) ); |
|
374 | + register_activation_hook(PLUGIN_FILE, array($this, 'db_install')); |
|
375 | + register_activation_hook(PLUGIN_FILE, array($this, 'cron_activation')); |
|
376 | 376 | |
377 | 377 | //remove the DB and CORN upon uninstallation |
378 | 378 | //using $this won't work here. |
379 | - register_uninstall_hook( PLUGIN_FILE, array( 'PLUGIN_BUILD', 'db_uninstall' ) ); |
|
380 | - register_uninstall_hook( PLUGIN_FILE, array( 'PLUGIN_BUILD', 'cron_uninstall' ) ); |
|
379 | + register_uninstall_hook(PLUGIN_FILE, array('PLUGIN_BUILD', 'db_uninstall')); |
|
380 | + register_uninstall_hook(PLUGIN_FILE, array('PLUGIN_BUILD', 'cron_uninstall')); |
|
381 | 381 | |
382 | - add_filter( 'rest_authentication_errors', array( $this, 'prevent_unauthorized_rest_access' ) ); |
|
382 | + add_filter('rest_authentication_errors', array($this, 'prevent_unauthorized_rest_access')); |
|
383 | 383 | |
384 | - add_action( 'init', array( $this, 'installation' ) ); |
|
385 | - add_action( 'init', array( $this, 'custom_cron_hook_cb' ) ); |
|
386 | - add_action( 'init', array( $this, 'cpt' ) ); |
|
384 | + add_action('init', array($this, 'installation')); |
|
385 | + add_action('init', array($this, 'custom_cron_hook_cb')); |
|
386 | + add_action('init', array($this, 'cpt')); |
|
387 | 387 | |
388 | 388 | $this->scripts(); |
389 | 389 | $this->widgets(); |
@@ -20,16 +20,16 @@ discard block |
||
20 | 20 | public function register_routes() { |
21 | 21 | |
22 | 22 | $version = '1'; |
23 | - $namespace = 'vendor/v' . $version; |
|
24 | - $base = 'route'; |
|
23 | + $namespace = 'vendor/v' . $version; |
|
24 | + $base = 'route'; |
|
25 | 25 | |
26 | 26 | //Available options for methods are CREATABLE, READABLE, EDITABLE, DELETABLE |
27 | 27 | register_rest_route( $namespace, '/' . $base, array( |
28 | - 'methods' => WP_REST_Server::READABLE, |
|
29 | - 'callback' => array( $this, 'callback' ), |
|
30 | - 'permission_callback' => array( $this, 'permission' ), |
|
31 | - 'args' => array('sample', 'list', 'of', 'args') |
|
32 | - )); |
|
28 | + 'methods' => WP_REST_Server::READABLE, |
|
29 | + 'callback' => array( $this, 'callback' ), |
|
30 | + 'permission_callback' => array( $this, 'permission' ), |
|
31 | + 'args' => array('sample', 'list', 'of', 'args') |
|
32 | + )); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | |
@@ -40,13 +40,13 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function callback() { |
42 | 42 | |
43 | - $params = $request->get_params(); |
|
44 | - $items = array(); |
|
45 | - $data = $this->prepare_item_for_response( $items, $request ); |
|
43 | + $params = $request->get_params(); |
|
44 | + $items = array(); |
|
45 | + $data = $this->prepare_item_for_response( $items, $request ); |
|
46 | 46 | |
47 | - if ( $data ) { |
|
48 | - return new WP_REST_Response( $data, 200 ); |
|
49 | - } else { |
|
47 | + if ( $data ) { |
|
48 | + return new WP_REST_Response( $data, 200 ); |
|
49 | + } else { |
|
50 | 50 | return new WP_Error( 'status_code', __( 'message', 'text-domain' ) ); |
51 | 51 | } |
52 | 52 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
2 | +if ( ! defined('ABSPATH')) exit; |
|
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Extending REST API framework of WordPress |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * @author Nirjhar Lo |
8 | 8 | * @package wp-plugin-framework |
9 | 9 | */ |
10 | -if ( ! class_exists( 'PLUGIN_CUSTOM_ROUTE' ) ) { |
|
10 | +if ( ! class_exists('PLUGIN_CUSTOM_ROUTE')) { |
|
11 | 11 | |
12 | 12 | class PLUGIN_CUSTOM_ROUTE extends WP_REST_Controller { |
13 | 13 | |
@@ -24,10 +24,10 @@ discard block |
||
24 | 24 | $base = 'route'; |
25 | 25 | |
26 | 26 | //Available options for methods are CREATABLE, READABLE, EDITABLE, DELETABLE |
27 | - register_rest_route( $namespace, '/' . $base, array( |
|
27 | + register_rest_route($namespace, '/' . $base, array( |
|
28 | 28 | 'methods' => WP_REST_Server::READABLE, |
29 | - 'callback' => array( $this, 'callback' ), |
|
30 | - 'permission_callback' => array( $this, 'permission' ), |
|
29 | + 'callback' => array($this, 'callback'), |
|
30 | + 'permission_callback' => array($this, 'permission'), |
|
31 | 31 | 'args' => array('sample', 'list', 'of', 'args') |
32 | 32 | )); |
33 | 33 | } |
@@ -42,12 +42,12 @@ discard block |
||
42 | 42 | |
43 | 43 | $params = $request->get_params(); |
44 | 44 | $items = array(); |
45 | - $data = $this->prepare_item_for_response( $items, $request ); |
|
45 | + $data = $this->prepare_item_for_response($items, $request); |
|
46 | 46 | |
47 | - if ( $data ) { |
|
48 | - return new WP_REST_Response( $data, 200 ); |
|
47 | + if ($data) { |
|
48 | + return new WP_REST_Response($data, 200); |
|
49 | 49 | } else { |
50 | - return new WP_Error( 'status_code', __( 'message', 'text-domain' ) ); |
|
50 | + return new WP_Error('status_code', __('message', 'text-domain')); |
|
51 | 51 | } |
52 | 52 | } |
53 | 53 | |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function permission() { |
61 | 61 | |
62 | - return current_user_can( 'manage_options' ); |
|
62 | + return current_user_can('manage_options'); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 |
@@ -1,5 +1,7 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
3 | 5 | |
4 | 6 | /** |
5 | 7 | * Extending REST API framework of WordPress |