| @@ -17,8 +17,17 @@ | ||
| 17 | 17 | */ |
| 18 | 18 | class ConvertKit_Admin_Restrict_Content { |
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | + * Holds the ConvertKit Tags resource class. | |
| 22 | + * | |
| 23 | + * @since 2.3.2 | |
| 24 | + * | |
| 25 | + * @var bool|ConvertKit_Resource_Tags | |
| 26 | + */ | |
| 27 | + public $tags = false; | |
| 28 | + | |
| 29 | + /** | |
| 21 | 30 | * Holds the ConvertKit Products resource class. |
| 22 | 31 | * |
| 23 | 32 | * @since 2.1.0 |
| 24 | 33 | * |
| @@ -51,21 +60,11 @@ | ||
| 51 | 60 | * @since 2.1.0 |
| 52 | 61 | */ |
| 53 | 62 | public function __construct() { |
| 54 | 63 | |
| 55 | - // Initialize classes that will be used. | |
| 56 | - $this->restrict_content_settings = new ConvertKit_Settings_Restrict_Content(); | |
| 57 | - | |
| 58 | - // Bail if Restrict Content isn't enabled. | |
| 59 | - if ( ! $this->restrict_content_settings->enabled() ) { | |
| 60 | - return; | |
| 61 | - } | |
| 62 | - | |
| 63 | - // Add New Member Content button. | |
| 64 | + // Add New Member Content Wizard button to Pages. | |
| 64 | 65 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts_and_css' ) ); |
| 65 | - foreach ( convertkit_get_supported_restrict_content_post_types() as $post_type ) { | |
| 66 | - add_filter( 'views_edit-' . $post_type, array( $this, 'output_wp_list_table_buttons' ) ); | |
| 67 | - } | |
| 66 | + add_filter( 'views_edit-page', array( $this, 'output_wp_list_table_buttons' ) ); | |
| 68 | 67 | |
| 69 | 68 | // Filter WP_List_Table by Restrict Content setting. |
| 70 | 69 | add_action( 'pre_get_posts', array( $this, 'filter_wp_list_table_output' ) ); |
| 71 | 70 | add_action( 'restrict_manage_posts', array( $this, 'output_wp_list_table_filters' ) ); |
| @@ -113,9 +112,9 @@ | ||
| 113 | 112 | return; |
| 114 | 113 | } |
| 115 | 114 | |
| 116 | 115 | // Don't filter if we're not querying a Post Type that supports Restricted Content. |
| 117 | - if ( ! in_array( $query->get( 'post_type' ), convertkit_get_supported_restrict_content_post_types(), true ) ) { | |
| 116 | + if ( ! in_array( $query->get( 'post_type' ), convertkit_get_supported_post_types(), true ) ) { | |
| 118 | 117 | return; |
| 119 | 118 | } |
| 120 | 119 | |
| 121 | 120 | // Build query. |
| @@ -169,9 +168,9 @@ | ||
| 169 | 168 | public function output_wp_list_table_buttons( $views ) { |
| 170 | 169 | |
| 171 | 170 | // If no API credentials have been set, don't output the button. |
| 172 | 171 | $settings = new ConvertKit_Settings(); |
| 173 | - if ( ! $settings->has_api_key_and_secret() ) { | |
| 172 | + if ( ! $settings->has_access_and_refresh_token() ) { | |
| 174 | 173 | return $views; |
| 175 | 174 | } |
| 176 | 175 | |
| 177 | 176 | // Get current post type that we're viewing. |
| @@ -181,9 +180,18 @@ | ||
| 181 | 180 | if ( ! $post_type ) { |
| 182 | 181 | return $views; |
| 183 | 182 | } |
| 184 | 183 | |
| 185 | - $views['convertkit_restrict_content_setup'] = '<a href="admin.php?page=convertkit-restrict-content-setup&post_type=' . esc_attr( $post_type ) . '" class="convertkit-action page-title-action hidden">' . esc_html__( 'Add New Member Content', 'convertkit' ) . '</a>'; | |
| 184 | + // Build URL for Restrict Content Setup Wizard. | |
| 185 | + $url = add_query_arg( | |
| 186 | + array( | |
| 187 | + 'page' => 'convertkit-restrict-content-setup', | |
| 188 | + 'ck_post_type' => $post_type, | |
| 189 | + ), | |
| 190 | + admin_url( 'options.php' ) | |
| 191 | + ); | |
| 192 | + | |
| 193 | + $views['convertkit_restrict_content_setup'] = '<a href="' . esc_attr( $url ) . '" class="convertkit-action page-title-action hidden">' . esc_html__( 'Add New Member Content', 'convertkit' ) . '</a>'; | |
| 186 | 194 | return $views; |
| 187 | 195 | |
| 188 | 196 | } |
| 189 | 197 | |
| @@ -197,23 +205,24 @@ | ||
| 197 | 205 | */ |
| 198 | 206 | public function output_wp_list_table_filters( $post_type ) { |
| 199 | 207 | |
| 200 | 208 | // Don't output filters if we're not viewing a Post Type that supports Restricted Content. |
| 201 | - if ( ! in_array( $post_type, convertkit_get_supported_restrict_content_post_types(), true ) ) { | |
| 209 | + if ( ! in_array( $post_type, convertkit_get_supported_post_types(), true ) ) { | |
| 202 | 210 | return; |
| 203 | 211 | } |
| 204 | 212 | |
| 205 | 213 | // Don't output filters if API credentials have not been defined in the Plugin's settings. |
| 206 | 214 | $settings = new ConvertKit_Settings(); |
| 207 | - if ( ! $settings->has_api_key_and_secret() ) { | |
| 215 | + if ( ! $settings->has_access_and_refresh_token() ) { | |
| 208 | 216 | return; |
| 209 | 217 | } |
| 210 | 218 | |
| 211 | - // Fetch Products. | |
| 219 | + // Fetch Products and Tags. | |
| 212 | 220 | $this->products = new ConvertKit_Resource_Products(); |
| 221 | + $this->tags = new ConvertKit_Resource_Tags(); | |
| 213 | 222 | |
| 214 | - // Don't display filter if no Products exist. | |
| 215 | - if ( ! $this->products->exist() ) { | |
| 223 | + // Don't display filter if no Tags and no Products exist. | |
| 224 | + if ( ! $this->products->exist() && ! $this->tags->exist() ) { | |
| 216 | 225 | return; |
| 217 | 226 | } |
| 218 | 227 | |
| 219 | 228 | // Output filter. |
| @@ -270,9 +279,9 @@ | ||
| 270 | 279 | return false; |
| 271 | 280 | } |
| 272 | 281 | |
| 273 | 282 | // Return whether Post Type is supported for Restrict Content functionality. |
| 274 | - return in_array( $screen->post_type, convertkit_get_supported_restrict_content_post_types(), true ); | |
| 283 | + return in_array( $screen->post_type, convertkit_get_supported_post_types(), true ); | |
| 275 | 284 | |
| 276 | 285 | } |
| 277 | 286 | |
| 278 | 287 | /** |