contact-forms
1 year ago
contact-forms.php
1 year ago
fluent-booking.php
9 months ago
index.php
1 month ago
newsletters.php
1 year ago
recommendation-page-post-type.php
1 year ago
recommendations-trait.php
3 months ago
siteleads.php
3 months ago
recommendation-page-post-type.php
124 lines
| 1 | <?php |
| 2 | use Kubio\Core\Importer; |
| 3 | |
| 4 | add_action( |
| 5 | 'init', |
| 6 | function () { |
| 7 | $recommendation_page_post_type = 'kubio_recommend_page'; |
| 8 | $args = array( |
| 9 | 'labels' => __( 'Recommendation pages', 'kubio' ), |
| 10 | 'public' => true, |
| 11 | 'has_archive' => false, |
| 12 | 'rewrite' => false, |
| 13 | 'show_in_rest' => true, |
| 14 | 'show_in_menu' => false, |
| 15 | 'show_in_nav_menus' => false, |
| 16 | 'exclude_from_search' => true, |
| 17 | 'supports' => array( 'editor', 'custom-fields', 'slug', 'revisions' ), |
| 18 | 'rest_controller_class' => 'WP_REST_Posts_Controller', |
| 19 | 'map_meta_cap' => true, |
| 20 | 'show_ui' => true, |
| 21 | 'hierarchical' => false, |
| 22 | ); |
| 23 | |
| 24 | register_post_type( $recommendation_page_post_type, $args ); |
| 25 | |
| 26 | register_post_meta( |
| 27 | $recommendation_page_post_type, |
| 28 | 'plugin_slug', |
| 29 | array( |
| 30 | 'type' => 'string', |
| 31 | 'single' => true, |
| 32 | 'show_in_rest' => true, |
| 33 | 'auth_callback' => '__return_true', |
| 34 | ) |
| 35 | ); |
| 36 | |
| 37 | register_post_meta( |
| 38 | $recommendation_page_post_type, |
| 39 | 'plugin_form_id', |
| 40 | array( |
| 41 | 'type' => 'integer', |
| 42 | 'single' => true, |
| 43 | 'show_in_rest' => true, |
| 44 | 'auth_callback' => '__return_true', |
| 45 | ) |
| 46 | ); |
| 47 | } |
| 48 | ); |
| 49 | function kubio_import_recommendation_page_post_type_template( $override = false ) { |
| 50 | $single_template = file_get_contents( KUBIO_ROOT_DIR . '/defaults/recommendations-templates/single-kubio_recommend_page.html' ); |
| 51 | |
| 52 | Importer::createTemplate( 'single-kubio_recommend_page', $single_template, $override, 'kubio' ); |
| 53 | } |
| 54 | function kubio_delete_recommend_page_for_plugin( $plugin_slug, $plugin_form_id ) { |
| 55 | // get kubio_recommend_page posts with the plugin_slug and plugin_form_id |
| 56 | $recommendation_page_posts = get_posts( |
| 57 | array( |
| 58 | 'post_type' => 'kubio_recommend_page', |
| 59 | 'posts_per_page' => -1, |
| 60 | 'meta_query' => array( |
| 61 | array( |
| 62 | 'key' => 'plugin_slug', |
| 63 | 'value' => $plugin_slug, |
| 64 | 'compare' => '=', |
| 65 | ), |
| 66 | array( |
| 67 | 'key' => 'plugin_form_id', |
| 68 | 'value' => $plugin_form_id, |
| 69 | 'compare' => '=', |
| 70 | ), |
| 71 | ), |
| 72 | 'fields' => 'ids', // Only get post IDs |
| 73 | ) |
| 74 | ); |
| 75 | |
| 76 | foreach ( $recommendation_page_posts as $recommendation_page_post_id ) { |
| 77 | wp_delete_post( $recommendation_page_post_id, true ); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | add_action( |
| 82 | 'delete_post', |
| 83 | /** |
| 84 | * @param int $post_id Post ID. |
| 85 | * @param WP_Post $post Post object. |
| 86 | */ |
| 87 | function ( $post_id, $post ) { |
| 88 | |
| 89 | $supported_post_types = array( |
| 90 | class_exists( \WPCF7_ContactForm::class ) ? \WPCF7_ContactForm::post_type : 'wpcf7_contact_form', |
| 91 | |
| 92 | ); |
| 93 | if ( ! in_array( $post->post_type, $supported_post_types, true ) ) { |
| 94 | return; |
| 95 | } |
| 96 | |
| 97 | $plugin_slug = null; |
| 98 | |
| 99 | switch ( $post->post_type ) { |
| 100 | case class_exists( \WPCF7_ContactForm::class ) ? \WPCF7_ContactForm::post_type : 'wpcf7_contact_form': |
| 101 | $plugin_slug = 'contact-form-7'; |
| 102 | break; |
| 103 | |
| 104 | } |
| 105 | |
| 106 | kubio_delete_recommend_page_for_plugin( |
| 107 | $plugin_slug, |
| 108 | $post_id |
| 109 | ); |
| 110 | }, |
| 111 | 10, |
| 112 | 2 |
| 113 | ); |
| 114 | |
| 115 | add_action( |
| 116 | 'fluent_booking/before_delete_calendar_event', |
| 117 | function ( $calendar ) { |
| 118 | kubio_delete_recommend_page_for_plugin( |
| 119 | 'fluent-booking', |
| 120 | $calendar->id |
| 121 | ); |
| 122 | } |
| 123 | ); |
| 124 |