| @@ -72,8 +72,20 @@ | ||
| 72 | 72 | $meta[ $key ] = $value; |
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | + /** | |
| 77 | + * Programmatically define ConvertKit settings for an individual Post, overriding those defined in the | |
| 78 | + * meta box. | |
| 79 | + * | |
| 80 | + * @since 2.4.4 | |
| 81 | + * | |
| 82 | + * @param array $meta Post Settings. | |
| 83 | + * @param int $post_id Post ID. | |
| 84 | + * @return array Post Settings. | |
| 85 | + */ | |
| 86 | + $meta = apply_filters( 'convertkit_post_settings', $meta, $this->post_id ); | |
| 87 | + | |
| 76 | 88 | // Assign Post's Settings to the object. |
| 77 | 89 | $this->settings = $meta; |
| 78 | 90 | |
| 79 | 91 | } |
| @@ -276,8 +288,32 @@ | ||
| 276 | 288 | |
| 277 | 289 | } |
| 278 | 290 | |
| 279 | 291 | /** |
| 292 | + * Returns all Post Meta rows stored against this Post for the Plugin's Post Meta key. | |
| 293 | + * | |
| 294 | + * Queries the database directly, as each row's meta ID is required to delete individual | |
| 295 | + * duplicate rows, which get_post_meta() doesn't return. | |
| 296 | + * | |
| 297 | + * @since 3.4.5 | |
| 298 | + * | |
| 299 | + * @return array Post Meta rows, oldest first. | |
| 300 | + */ | |
| 301 | + public function get_meta_rows() { | |
| 302 | + | |
| 303 | + global $wpdb; | |
| 304 | + | |
| 305 | + return $wpdb->get_results( | |
| 306 | + $wpdb->prepare( | |
| 307 | + "SELECT meta_id, meta_value FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = %s ORDER BY meta_id ASC", | |
| 308 | + $this->post_id, | |
| 309 | + self::POST_META_KEY | |
| 310 | + ) | |
| 311 | + ); | |
| 312 | + | |
| 313 | + } | |
| 314 | + | |
| 315 | + /** | |
| 280 | 316 | * Saves Post settings to the Post. |
| 281 | 317 | * |
| 282 | 318 | * @since 1.9.6 |
| 283 | 319 | * |
| @@ -301,11 +337,11 @@ | ||
| 301 | 337 | public function get_default_settings() { |
| 302 | 338 | |
| 303 | 339 | $defaults = array( |
| 304 | 340 | 'form' => '-1', // -1: Plugin Default Form, 0: No Form, 1+: Specific Form ID on ConvertKit. |
| 305 | - 'landing_page' => '', | |
| 306 | - 'tag' => '', | |
| 307 | - 'restrict_content' => '', | |
| 341 | + 'landing_page' => '0', // 0: None, 1+: Specific Landing Page ID. | |
| 342 | + 'tag' => '0', // 0: None, 1+: Specific Tag ID. | |
| 343 | + 'restrict_content' => '0', // 0: None, form_<id> / tag_<id> / product_<id>: restrict to that resource. | |
| 308 | 344 | ); |
| 309 | 345 | |
| 310 | 346 | /** |
| 311 | 347 | * The default settings, used to populate the Post's Settings when a Post has no Settings. |
| @@ -312,10 +348,11 @@ | ||
| 312 | 348 | * |
| 313 | 349 | * @since 1.9.6 |
| 314 | 350 | * |
| 315 | 351 | * @param array $defaults Default Settings. |
| 352 | + * @param int $post_id Post ID. | |
| 316 | 353 | */ |
| 317 | - $defaults = apply_filters( 'convertkit_post_get_default_settings', $defaults ); | |
| 354 | + $defaults = apply_filters( 'convertkit_post_get_default_settings', $defaults, $this->post_id ); | |
| 318 | 355 | |
| 319 | 356 | return $defaults; |
| 320 | 357 | |
| 321 | 358 | } |