| @@ -21,18 +21,11 @@ | ||
| 21 | 21 | * @since 1.9.6 |
| 22 | 22 | */ |
| 23 | 23 | public function __construct() { |
| 24 | 24 | |
| 25 | - // Load CSS and JS when adding/editing Categories. | |
| 26 | 25 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
| 27 | 26 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) ); |
| 28 | - | |
| 29 | - // Add Category. | |
| 30 | - add_action( 'category_add_form_fields', array( $this, 'add_category_form_fields' ), 10 ); | |
| 31 | - add_action( 'created_category', array( $this, 'save_category_fields' ), 20 ); | |
| 32 | - | |
| 33 | - // Edit Category. | |
| 34 | - add_action( 'category_edit_form_fields', array( $this, 'edit_category_form_fields' ), 20 ); | |
| 27 | + add_action( 'category_edit_form_fields', array( $this, 'category_form_fields' ), 20 ); | |
| 35 | 28 | add_action( 'edited_category', array( $this, 'save_category_fields' ), 20 ); |
| 36 | 29 | |
| 37 | 30 | } |
| 38 | 31 | |
| @@ -45,13 +38,28 @@ | ||
| 45 | 38 | * @param string $hook Hook. |
| 46 | 39 | */ |
| 47 | 40 | public function enqueue_scripts( $hook ) { |
| 48 | 41 | |
| 49 | - // Don't load scripts if not editing a Category. | |
| 50 | - if ( ! $this->is_category_edit_screen( $hook ) ) { | |
| 42 | + // Bail if we are not editing a Term. | |
| 43 | + if ( $hook !== 'term.php' ) { | |
| 51 | 44 | return; |
| 52 | 45 | } |
| 53 | 46 | |
| 47 | + // Bail if we are not editing a Category. | |
| 48 | + if ( ! function_exists( 'get_current_screen' ) ) { | |
| 49 | + return; | |
| 50 | + } | |
| 51 | + $screen = get_current_screen(); | |
| 52 | + if ( $screen->id !== 'edit-category' ) { | |
| 53 | + return; | |
| 54 | + } | |
| 55 | + | |
| 56 | + // Bail if the API hasn't been configured. | |
| 57 | + $settings = new ConvertKit_Settings(); | |
| 58 | + if ( ! $settings->has_api_key_and_secret() ) { | |
| 59 | + return; | |
| 60 | + } | |
| 61 | + | |
| 54 | 62 | // Enqueue Select2 JS. |
| 55 | 63 | convertkit_select2_enqueue_scripts(); |
| 56 | 64 | |
| 57 | 65 | /** |
| @@ -68,24 +76,14 @@ | ||
| 68 | 76 | * Enqueue CSS when editing a Category that outputs |
| 69 | 77 | * ConvertKit Plugin settings. |
| 70 | 78 | * |
| 71 | 79 | * @since 1.9.6.4 |
| 72 | - * | |
| 73 | - * @param string $hook Hook. | |
| 74 | 80 | */ |
| 75 | - public function enqueue_styles( $hook ) { | |
| 81 | + public function enqueue_styles() { | |
| 76 | 82 | |
| 77 | - // Don't load scripts if not editing a Category. | |
| 78 | - if ( ! $this->is_category_edit_screen( $hook ) ) { | |
| 79 | - return; | |
| 80 | - } | |
| 81 | - | |
| 82 | 83 | // Enqueue Select2 CSS. |
| 83 | 84 | convertkit_select2_enqueue_styles(); |
| 84 | 85 | |
| 85 | - // Enqueue Category CSS. | |
| 86 | - wp_enqueue_style( 'convertkit-category', CONVERTKIT_PLUGIN_URL . 'resources/backend/css/category.css', array(), CONVERTKIT_PLUGIN_VERSION ); | |
| 87 | - | |
| 88 | 86 | /** |
| 89 | 87 | * Enqueue CSS when editing a Category that outputs |
| 90 | 88 | * ConvertKit Plugin settings. |
| 91 | 89 | * |
| @@ -95,63 +93,8 @@ | ||
| 95 | 93 | |
| 96 | 94 | } |
| 97 | 95 | |
| 98 | 96 | /** |
| 99 | - * Determine if the current request is for editing a Category. | |
| 100 | - * | |
| 101 | - * @since 2.0.3 | |
| 102 | - * | |
| 103 | - * @param string $hook Hook. | |
| 104 | - * @return bool Is category edit screen request | |
| 105 | - */ | |
| 106 | - private function is_category_edit_screen( $hook ) { | |
| 107 | - | |
| 108 | - // Bail if we are not editing a Term. | |
| 109 | - if ( $hook !== 'term.php' && $hook !== 'edit-tags.php' ) { | |
| 110 | - return false; | |
| 111 | - } | |
| 112 | - | |
| 113 | - // Bail if we are not editing a Category. | |
| 114 | - if ( ! function_exists( 'get_current_screen' ) ) { | |
| 115 | - return false; | |
| 116 | - } | |
| 117 | - $screen = get_current_screen(); | |
| 118 | - | |
| 119 | - if ( $screen->id !== 'edit-category' ) { | |
| 120 | - return false; | |
| 121 | - } | |
| 122 | - | |
| 123 | - // Bail if the API hasn't been configured. | |
| 124 | - $settings = new ConvertKit_Settings(); | |
| 125 | - if ( ! $settings->has_api_key_and_secret() ) { | |
| 126 | - return false; | |
| 127 | - } | |
| 128 | - | |
| 129 | - return true; | |
| 130 | - } | |
| 131 | - | |
| 132 | - /** | |
| 133 | - * Display the ConvertKit Forms dropdown when adding a Category | |
| 134 | - * | |
| 135 | - * @since 2.0.3 | |
| 136 | - */ | |
| 137 | - public function add_category_form_fields() { | |
| 138 | - | |
| 139 | - // Don't show the form fields if the API hasn't been configured. | |
| 140 | - $settings = new ConvertKit_Settings(); | |
| 141 | - if ( ! $settings->has_api_key_and_secret() ) { | |
| 142 | - return; | |
| 143 | - } | |
| 144 | - | |
| 145 | - // Fetch Forms. | |
| 146 | - $convertkit_forms = new ConvertKit_Resource_Forms(); | |
| 147 | - | |
| 148 | - // Load view. | |
| 149 | - include CONVERTKIT_PLUGIN_PATH . '/views/backend/term/fields-add.php'; | |
| 150 | - | |
| 151 | - } | |
| 152 | - | |
| 153 | - /** | |
| 154 | 97 | * Display the ConvertKit Forms dropdown when editing a Category |
| 155 | 98 | * |
| 156 | 99 | * @since 1.9.6 |
| 157 | 100 | * |
| @@ -156,9 +99,9 @@ | ||
| 156 | 99 | * @since 1.9.6 |
| 157 | 100 | * |
| 158 | 101 | * @param WP_Term $term Category. |
| 159 | 102 | */ |
| 160 | - public function edit_category_form_fields( $term ) { | |
| 103 | + public function category_form_fields( $term ) { | |
| 161 | 104 | |
| 162 | 105 | // Don't show the form fields if the API hasn't been configured. |
| 163 | 106 | $settings = new ConvertKit_Settings(); |
| 164 | 107 | if ( ! $settings->has_api_key_and_secret() ) { |
| @@ -168,10 +111,10 @@ | ||
| 168 | 111 | // Fetch Category Settings and Forms. |
| 169 | 112 | $convertkit_term = new ConvertKit_Term( $term->term_id ); |
| 170 | 113 | $convertkit_forms = new ConvertKit_Resource_Forms(); |
| 171 | 114 | |
| 172 | - // Load view. | |
| 173 | - include CONVERTKIT_PLUGIN_PATH . '/views/backend/term/fields-edit.php'; | |
| 115 | + // Load metabox view. | |
| 116 | + include CONVERTKIT_PLUGIN_PATH . '/views/backend/term/fields.php'; | |
| 174 | 117 | |
| 175 | 118 | } |
| 176 | 119 | |
| 177 | 120 | /** |
| @@ -188,9 +131,9 @@ | ||
| 188 | 131 | return; |
| 189 | 132 | } |
| 190 | 133 | |
| 191 | 134 | // Bail if the nonce verification fails. |
| 192 | - if ( ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['wp-convertkit-save-meta-nonce'] ) ), 'wp-convertkit-save-meta' ) ) { | |
| 135 | + if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['wp-convertkit-save-meta-nonce'] ) ), 'wp-convertkit-save-meta' ) ) { | |
| 193 | 136 | return; |
| 194 | 137 | } |
| 195 | 138 | |
| 196 | 139 | // Bail if no ConvertKit settings were posted. |