| 1 |
<?php |
| 2 |
/** |
| 3 |
* ConvertKit Plugin Sidebar class. |
| 4 |
* |
| 5 |
* @package ConvertKit |
| 6 |
* @author ConvertKit |
| 7 |
*/ |
| 8 |
|
| 9 |
/** |
| 10 |
* ConvertKit Plugin Sidebar definition for Gutenberg. |
| 11 |
* |
| 12 |
* @package ConvertKit |
| 13 |
* @author ConvertKit |
| 14 |
*/ |
| 15 |
class ConvertKit_Plugin_Sidebar { |
| 16 |
|
| 17 |
/** |
| 18 |
* Registers this plugin sidebar with the ConvertKit Plugin. |
| 19 |
* |
| 20 |
* @since 3.3.0 |
| 21 |
* |
| 22 |
* @param array $plugin_sidebars Plugin Sidebars to Register. |
| 23 |
* @return array Plugin Sidebars to Register |
| 24 |
*/ |
| 25 |
public function register( $plugin_sidebars ) { |
| 26 |
|
| 27 |
// If the request is for the frontend, return the minimum sidebar definition required |
| 28 |
// for register_post_meta(). |
| 29 |
if ( ! $this->is_admin_frontend_editor_or_admin_rest_request() ) { |
| 30 |
$plugin_sidebars[ $this->get_name() ] = array( |
| 31 |
'name' => $this->get_name(), |
| 32 |
'minimum_capability' => $this->get_minimum_capability(), |
| 33 |
'meta_key' => $this->get_meta_key(), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key |
| 34 |
'title' => $this->get_title(), |
| 35 |
'attributes' => $this->get_attributes(), |
| 36 |
'default_values' => $this->get_default_values(), |
| 37 |
); |
| 38 |
|
| 39 |
return $plugin_sidebars; |
| 40 |
} |
| 41 |
|
| 42 |
$plugin_sidebars[ $this->get_name() ] = array( |
| 43 |
'name' => $this->get_name(), |
| 44 |
'minimum_capability' => $this->get_minimum_capability(), |
| 45 |
'meta_key' => $this->get_meta_key(), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key |
| 46 |
'title' => $this->get_title(), |
| 47 |
'icon' => $this->get_icon(), |
| 48 |
'gutenberg_icon' => convertkit_get_file_contents( CONVERTKIT_PLUGIN_PATH . '/' . $this->get_icon() ), |
| 49 |
'fields' => $this->get_fields(), |
| 50 |
'attributes' => $this->get_attributes(), |
| 51 |
'default_values' => $this->get_default_values(), |
| 52 |
); |
| 53 |
|
| 54 |
return $plugin_sidebars; |
| 55 |
|
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* Returns this plugin sidebar's meta key. |
| 60 |
* |
| 61 |
* @since 3.3.0 |
| 62 |
*/ |
| 63 |
public function get_name() { |
| 64 |
|
| 65 |
return ''; |
| 66 |
|
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Returns this plugin sidebar's minimum capability required |
| 71 |
* for displaying and permitting edits to the settings. |
| 72 |
* |
| 73 |
* @since 3.3.0 |
| 74 |
* |
| 75 |
* @return string |
| 76 |
*/ |
| 77 |
public function get_minimum_capability() { |
| 78 |
|
| 79 |
return 'edit_posts'; |
| 80 |
|
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Returns this plugin sidebar's meta key. |
| 85 |
* |
| 86 |
* @since 3.3.0 |
| 87 |
* |
| 88 |
* @return string |
| 89 |
*/ |
| 90 |
public function get_meta_key() { |
| 91 |
|
| 92 |
return ''; |
| 93 |
|
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Returns this plugin sidebar's title. |
| 98 |
* |
| 99 |
* @since 3.3.0 |
| 100 |
*/ |
| 101 |
public function get_title() { |
| 102 |
|
| 103 |
return ''; |
| 104 |
|
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* Returns this plugin sidebar's icon. |
| 109 |
* |
| 110 |
* @since 3.3.0 |
| 111 |
*/ |
| 112 |
public function get_icon() { |
| 113 |
|
| 114 |
return ''; |
| 115 |
|
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* Returns this plugin sidebar's attributes. |
| 120 |
* |
| 121 |
* @since 3.3.0 |
| 122 |
* |
| 123 |
* @return array |
| 124 |
*/ |
| 125 |
public function get_attributes() { |
| 126 |
|
| 127 |
return array(); |
| 128 |
|
| 129 |
} |
| 130 |
|
| 131 |
/** |
| 132 |
* Returns this plugin sidebar's Fields |
| 133 |
* |
| 134 |
* @since 3.3.0 |
| 135 |
* |
| 136 |
* @return array |
| 137 |
*/ |
| 138 |
public function get_fields() { |
| 139 |
|
| 140 |
return array(); |
| 141 |
|
| 142 |
} |
| 143 |
|
| 144 |
/** |
| 145 |
* Returns this plugin sidebar's Default Values |
| 146 |
* |
| 147 |
* @since 3.3.0 |
| 148 |
* |
| 149 |
* @return array |
| 150 |
*/ |
| 151 |
public function get_default_values() { |
| 152 |
|
| 153 |
return array(); |
| 154 |
|
| 155 |
} |
| 156 |
|
| 157 |
/** |
| 158 |
* Returns the given plugin sidebar's field's Default Value |
| 159 |
* |
| 160 |
* @since 3.3.0 |
| 161 |
* |
| 162 |
* @param string $field Field Name. |
| 163 |
* @return string |
| 164 |
*/ |
| 165 |
public function get_default_value( $field ) { |
| 166 |
|
| 167 |
$defaults = $this->get_default_values(); |
| 168 |
if ( isset( $defaults[ $field ] ) ) { |
| 169 |
return $defaults[ $field ]; |
| 170 |
} |
| 171 |
|
| 172 |
return ''; |
| 173 |
|
| 174 |
} |
| 175 |
|
| 176 |
/** |
| 177 |
* Determines if the request is a WordPress REST API request |
| 178 |
* made by a logged in WordPress user who has the capability to edit posts. |
| 179 |
* |
| 180 |
* @since 3.3.0 |
| 181 |
* |
| 182 |
* @return bool |
| 183 |
*/ |
| 184 |
public function is_admin_rest_request() { |
| 185 |
|
| 186 |
return defined( 'REST_REQUEST' ) && REST_REQUEST && current_user_can( 'edit_posts' ); |
| 187 |
|
| 188 |
} |
| 189 |
|
| 190 |
/** |
| 191 |
* Determines if the request is for the WordPress Administration, frontend editor or REST API request. |
| 192 |
* |
| 193 |
* @since 3.3.0 |
| 194 |
* |
| 195 |
* @return bool |
| 196 |
*/ |
| 197 |
public function is_admin_frontend_editor_or_admin_rest_request() { |
| 198 |
|
| 199 |
return WP_ConvertKit()->is_admin_or_frontend_editor() || $this->is_admin_rest_request(); |
| 200 |
|
| 201 |
} |
| 202 |
|
| 203 |
} |
| 204 |
|