@@ -11,67 +11,67 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | class Meta_Box { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @var Api_Service_Ext |
|
| 16 | - */ |
|
| 17 | - private $api_service; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * @var Recipe_Lift_Strategy |
|
| 21 | - */ |
|
| 22 | - private $recipe_lift_strategy; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @param Api_Service_Ext $api_service |
|
| 26 | - * @param Recipe_Lift_Strategy $recipe_lift_strategy |
|
| 27 | - */ |
|
| 28 | - public function __construct( Api_Service_Ext $api_service, Recipe_Lift_Strategy $recipe_lift_strategy ) { |
|
| 29 | - $this->api_service = $api_service; |
|
| 30 | - $this->recipe_lift_strategy = $recipe_lift_strategy; |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Register Hooks. |
|
| 35 | - * |
|
| 36 | - * @return void |
|
| 37 | - */ |
|
| 38 | - public function register_hooks() { |
|
| 39 | - add_action( 'wl_ingredient_metabox_html', array( $this, 'ingredients_html' ) ); |
|
| 40 | - add_action( 'wp_ajax_wl_update_ingredient_post_meta', array( $this, 'update_ingredient_post_meta' ) ); |
|
| 41 | - add_action( 'wp_ajax_wl_ingredient_autocomplete', array( $this, 'wl_ingredient_autocomplete' ) ); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Ingredients HTML. |
|
| 46 | - */ |
|
| 47 | - public function ingredients_html() { |
|
| 48 | - |
|
| 49 | - // Enqueue scripts. |
|
| 50 | - $this->enqueue_scripts(); |
|
| 51 | - |
|
| 52 | - $recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( get_the_ID() ); |
|
| 53 | - if ( empty( $recipe_ids ) ) { |
|
| 54 | - return; |
|
| 55 | - } |
|
| 56 | - foreach ( $recipe_ids as $key => $recipe_id ) { |
|
| 57 | - $recipe_json_ld = get_post_meta( $recipe_id, '_wl_main_ingredient_jsonld', true ); |
|
| 58 | - if ( ! $recipe_json_ld ) { |
|
| 59 | - continue; |
|
| 60 | - } |
|
| 61 | - $recipe = json_decode( $recipe_json_ld, true ); |
|
| 62 | - if ( ! isset( $recipe['name'] ) ) { |
|
| 63 | - continue; |
|
| 64 | - } |
|
| 65 | - ?> |
|
| 14 | + /** |
|
| 15 | + * @var Api_Service_Ext |
|
| 16 | + */ |
|
| 17 | + private $api_service; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * @var Recipe_Lift_Strategy |
|
| 21 | + */ |
|
| 22 | + private $recipe_lift_strategy; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @param Api_Service_Ext $api_service |
|
| 26 | + * @param Recipe_Lift_Strategy $recipe_lift_strategy |
|
| 27 | + */ |
|
| 28 | + public function __construct( Api_Service_Ext $api_service, Recipe_Lift_Strategy $recipe_lift_strategy ) { |
|
| 29 | + $this->api_service = $api_service; |
|
| 30 | + $this->recipe_lift_strategy = $recipe_lift_strategy; |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Register Hooks. |
|
| 35 | + * |
|
| 36 | + * @return void |
|
| 37 | + */ |
|
| 38 | + public function register_hooks() { |
|
| 39 | + add_action( 'wl_ingredient_metabox_html', array( $this, 'ingredients_html' ) ); |
|
| 40 | + add_action( 'wp_ajax_wl_update_ingredient_post_meta', array( $this, 'update_ingredient_post_meta' ) ); |
|
| 41 | + add_action( 'wp_ajax_wl_ingredient_autocomplete', array( $this, 'wl_ingredient_autocomplete' ) ); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Ingredients HTML. |
|
| 46 | + */ |
|
| 47 | + public function ingredients_html() { |
|
| 48 | + |
|
| 49 | + // Enqueue scripts. |
|
| 50 | + $this->enqueue_scripts(); |
|
| 51 | + |
|
| 52 | + $recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( get_the_ID() ); |
|
| 53 | + if ( empty( $recipe_ids ) ) { |
|
| 54 | + return; |
|
| 55 | + } |
|
| 56 | + foreach ( $recipe_ids as $key => $recipe_id ) { |
|
| 57 | + $recipe_json_ld = get_post_meta( $recipe_id, '_wl_main_ingredient_jsonld', true ); |
|
| 58 | + if ( ! $recipe_json_ld ) { |
|
| 59 | + continue; |
|
| 60 | + } |
|
| 61 | + $recipe = json_decode( $recipe_json_ld, true ); |
|
| 62 | + if ( ! isset( $recipe['name'] ) ) { |
|
| 63 | + continue; |
|
| 64 | + } |
|
| 65 | + ?> |
|
| 66 | 66 | <div class="wl-recipe-ingredient"> |
| 67 | 67 | <?php |
| 68 | - $allowed_tags = array( |
|
| 69 | - 'p' => array(), |
|
| 70 | - 'strong' => array(), |
|
| 71 | - ); |
|
| 72 | - // translators: %s is the ingredient name. |
|
| 73 | - echo wp_kses( sprintf( '<p>' . __( 'The main ingredient is', 'wordlift' ) . ' <strong>%s</strong></p>', esc_html( $recipe['name'] ) ), $allowed_tags ); |
|
| 74 | - ?> |
|
| 68 | + $allowed_tags = array( |
|
| 69 | + 'p' => array(), |
|
| 70 | + 'strong' => array(), |
|
| 71 | + ); |
|
| 72 | + // translators: %s is the ingredient name. |
|
| 73 | + echo wp_kses( sprintf( '<p>' . __( 'The main ingredient is', 'wordlift' ) . ' <strong>%s</strong></p>', esc_html( $recipe['name'] ) ), $allowed_tags ); |
|
| 74 | + ?> |
|
| 75 | 75 | <form class="wl-recipe-ingredient-form" id="wl-recipe-ingredient-form-<?php echo esc_attr( $key ); ?>"> |
| 76 | 76 | <div class="wl-recipe-ingredient__field"> |
| 77 | 77 | <label for="wl-recipe-ingredient__field-<?php echo esc_attr( $recipe['name'] ) . '-' . esc_attr( $key ); ?>"><?php echo esc_html__( 'Replace the main ingredient', 'wordlift' ); ?>: </label> |
@@ -82,136 +82,136 @@ discard block |
||
| 82 | 82 | </form> |
| 83 | 83 | </div> |
| 84 | 84 | <?php |
| 85 | - } |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Ingredient Autocomplete. |
|
| 90 | - */ |
|
| 91 | - public function wl_ingredient_autocomplete() { |
|
| 92 | - |
|
| 93 | - check_ajax_referer( 'wl-ac-ingredient-nonce' ); |
|
| 94 | - |
|
| 95 | - // Return error if the query param is empty. |
|
| 96 | - if ( ! empty( $_REQUEST['query'] ) ) { // Input var okay. |
|
| 97 | - $query = sanitize_text_field( wp_unslash( $_REQUEST['query'] ) ); // Input var okay. |
|
| 98 | - } else { |
|
| 99 | - wp_send_json_error( |
|
| 100 | - array( |
|
| 101 | - 'message' => __( 'The query param is empty.', 'wordlift' ), |
|
| 102 | - ) |
|
| 103 | - ); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // Get new JSON LD Data. |
|
| 107 | - $new_json_ld = $this->recipe_lift_strategy->get_json_ld_data( $query ); |
|
| 108 | - |
|
| 109 | - $data = json_decode( $new_json_ld ); |
|
| 110 | - |
|
| 111 | - // Clear any buffer. |
|
| 112 | - ob_clean(); |
|
| 113 | - |
|
| 114 | - if ( $data ) { |
|
| 115 | - wp_send_json_success( array( $data->name ) ); |
|
| 116 | - } else { |
|
| 117 | - wp_send_json_error( |
|
| 118 | - array( |
|
| 119 | - 'message' => __( 'No results found.', 'wordlift' ), |
|
| 120 | - ) |
|
| 121 | - ); |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Update Ingredient Post Meta. |
|
| 127 | - */ |
|
| 128 | - public function update_ingredient_post_meta() { |
|
| 129 | - check_ajax_referer( 'wl-ingredient-nonce' ); |
|
| 130 | - |
|
| 131 | - // Check if current user can edit posts. |
|
| 132 | - if ( ! current_user_can( 'edit_posts' ) ) { |
|
| 133 | - wp_send_json_error( |
|
| 134 | - array( |
|
| 135 | - 'message' => __( 'You are not allowed to edit posts.', 'wordlift' ), |
|
| 136 | - 'btnText' => __( 'Denied!', 'wordlift' ), |
|
| 137 | - ) |
|
| 138 | - ); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - // Return error if the recipe id is empty. |
|
| 142 | - if ( ! empty( $_REQUEST['recipe_id'] ) ) { // Input var okay. |
|
| 143 | - $recipe_id = sanitize_text_field( wp_unslash( $_REQUEST['recipe_id'] ) ); // Input var okay. |
|
| 144 | - } else { |
|
| 145 | - wp_send_json_error( |
|
| 146 | - array( |
|
| 147 | - 'message' => __( 'The recipe id is empty.', 'wordlift' ), |
|
| 148 | - 'btnText' => __( 'Failed!', 'wordlift' ), |
|
| 149 | - ) |
|
| 150 | - ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // Return error if the main ingredient is empty. |
|
| 154 | - if ( ! empty( $_REQUEST['main_ingredient'] ) ) { |
|
| 155 | - $main_ingredient = sanitize_text_field( wp_unslash( $_REQUEST['main_ingredient'] ) ); |
|
| 156 | - } else { |
|
| 157 | - wp_send_json_error( |
|
| 158 | - array( |
|
| 159 | - 'message' => __( 'The main ingredient is empty.', 'wordlift' ), |
|
| 160 | - 'btnText' => __( 'Failed!', 'wordlift' ), |
|
| 161 | - ) |
|
| 162 | - ); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // Get new JSON LD Data. |
|
| 166 | - $new_json_ld = $this->recipe_lift_strategy->get_json_ld_data( $main_ingredient ); |
|
| 167 | - |
|
| 168 | - if ( $new_json_ld ) { |
|
| 169 | - // Update the recipe post meta for JSON-LD. |
|
| 170 | - $update = update_post_meta( $recipe_id, '_wl_main_ingredient_jsonld', $new_json_ld ); |
|
| 171 | - if ( $update ) { |
|
| 172 | - wp_send_json_success( |
|
| 173 | - array( |
|
| 174 | - 'message' => __( 'The main ingredient has been updated.', 'wordlift' ), |
|
| 175 | - 'btnText' => __( 'Saved!', 'wordlift' ), |
|
| 176 | - ) |
|
| 177 | - ); |
|
| 178 | - } else { |
|
| 179 | - wp_send_json( |
|
| 180 | - array( |
|
| 181 | - 'same' => true, |
|
| 182 | - 'message' => __( 'You didn\'t updated the main ingredient value.', 'wordlift' ), |
|
| 183 | - 'btnText' => __( 'Save', 'wordlift' ), |
|
| 184 | - ) |
|
| 185 | - ); |
|
| 186 | - } |
|
| 187 | - } else { |
|
| 188 | - wp_send_json_error( |
|
| 189 | - array( |
|
| 190 | - 'message' => __( 'Failed to Update Recipe Ingredient.', 'wordlift' ), |
|
| 191 | - 'btnText' => __( 'Failed!', 'wordlift' ), |
|
| 192 | - ) |
|
| 193 | - ); |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Enqueue Scripts. |
|
| 199 | - */ |
|
| 200 | - public function enqueue_scripts() { |
|
| 201 | - wp_enqueue_script( 'wl-meta-box-ingredient', WL_DIR_URL . 'js/dist/ingredients-meta-box.js', array( 'jquery', 'jquery-ui-autocomplete' ), WORDLIFT_VERSION, true ); |
|
| 202 | - |
|
| 203 | - wp_localize_script( |
|
| 204 | - 'wl-meta-box-ingredient', |
|
| 205 | - '_wlRecipeIngredient', |
|
| 206 | - array( |
|
| 207 | - 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
| 208 | - 'nonce' => wp_create_nonce( 'wl-ingredient-nonce' ), |
|
| 209 | - 'acNonce' => wp_create_nonce( 'wl-ac-ingredient-nonce' ), |
|
| 210 | - 'texts' => array( |
|
| 211 | - 'saving' => __( 'Saving...', 'wordlift' ), |
|
| 212 | - 'noResults' => __( 'No results found.', 'wordlift' ), |
|
| 213 | - ), |
|
| 214 | - ) |
|
| 215 | - ); |
|
| 216 | - } |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Ingredient Autocomplete. |
|
| 90 | + */ |
|
| 91 | + public function wl_ingredient_autocomplete() { |
|
| 92 | + |
|
| 93 | + check_ajax_referer( 'wl-ac-ingredient-nonce' ); |
|
| 94 | + |
|
| 95 | + // Return error if the query param is empty. |
|
| 96 | + if ( ! empty( $_REQUEST['query'] ) ) { // Input var okay. |
|
| 97 | + $query = sanitize_text_field( wp_unslash( $_REQUEST['query'] ) ); // Input var okay. |
|
| 98 | + } else { |
|
| 99 | + wp_send_json_error( |
|
| 100 | + array( |
|
| 101 | + 'message' => __( 'The query param is empty.', 'wordlift' ), |
|
| 102 | + ) |
|
| 103 | + ); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // Get new JSON LD Data. |
|
| 107 | + $new_json_ld = $this->recipe_lift_strategy->get_json_ld_data( $query ); |
|
| 108 | + |
|
| 109 | + $data = json_decode( $new_json_ld ); |
|
| 110 | + |
|
| 111 | + // Clear any buffer. |
|
| 112 | + ob_clean(); |
|
| 113 | + |
|
| 114 | + if ( $data ) { |
|
| 115 | + wp_send_json_success( array( $data->name ) ); |
|
| 116 | + } else { |
|
| 117 | + wp_send_json_error( |
|
| 118 | + array( |
|
| 119 | + 'message' => __( 'No results found.', 'wordlift' ), |
|
| 120 | + ) |
|
| 121 | + ); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Update Ingredient Post Meta. |
|
| 127 | + */ |
|
| 128 | + public function update_ingredient_post_meta() { |
|
| 129 | + check_ajax_referer( 'wl-ingredient-nonce' ); |
|
| 130 | + |
|
| 131 | + // Check if current user can edit posts. |
|
| 132 | + if ( ! current_user_can( 'edit_posts' ) ) { |
|
| 133 | + wp_send_json_error( |
|
| 134 | + array( |
|
| 135 | + 'message' => __( 'You are not allowed to edit posts.', 'wordlift' ), |
|
| 136 | + 'btnText' => __( 'Denied!', 'wordlift' ), |
|
| 137 | + ) |
|
| 138 | + ); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + // Return error if the recipe id is empty. |
|
| 142 | + if ( ! empty( $_REQUEST['recipe_id'] ) ) { // Input var okay. |
|
| 143 | + $recipe_id = sanitize_text_field( wp_unslash( $_REQUEST['recipe_id'] ) ); // Input var okay. |
|
| 144 | + } else { |
|
| 145 | + wp_send_json_error( |
|
| 146 | + array( |
|
| 147 | + 'message' => __( 'The recipe id is empty.', 'wordlift' ), |
|
| 148 | + 'btnText' => __( 'Failed!', 'wordlift' ), |
|
| 149 | + ) |
|
| 150 | + ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // Return error if the main ingredient is empty. |
|
| 154 | + if ( ! empty( $_REQUEST['main_ingredient'] ) ) { |
|
| 155 | + $main_ingredient = sanitize_text_field( wp_unslash( $_REQUEST['main_ingredient'] ) ); |
|
| 156 | + } else { |
|
| 157 | + wp_send_json_error( |
|
| 158 | + array( |
|
| 159 | + 'message' => __( 'The main ingredient is empty.', 'wordlift' ), |
|
| 160 | + 'btnText' => __( 'Failed!', 'wordlift' ), |
|
| 161 | + ) |
|
| 162 | + ); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // Get new JSON LD Data. |
|
| 166 | + $new_json_ld = $this->recipe_lift_strategy->get_json_ld_data( $main_ingredient ); |
|
| 167 | + |
|
| 168 | + if ( $new_json_ld ) { |
|
| 169 | + // Update the recipe post meta for JSON-LD. |
|
| 170 | + $update = update_post_meta( $recipe_id, '_wl_main_ingredient_jsonld', $new_json_ld ); |
|
| 171 | + if ( $update ) { |
|
| 172 | + wp_send_json_success( |
|
| 173 | + array( |
|
| 174 | + 'message' => __( 'The main ingredient has been updated.', 'wordlift' ), |
|
| 175 | + 'btnText' => __( 'Saved!', 'wordlift' ), |
|
| 176 | + ) |
|
| 177 | + ); |
|
| 178 | + } else { |
|
| 179 | + wp_send_json( |
|
| 180 | + array( |
|
| 181 | + 'same' => true, |
|
| 182 | + 'message' => __( 'You didn\'t updated the main ingredient value.', 'wordlift' ), |
|
| 183 | + 'btnText' => __( 'Save', 'wordlift' ), |
|
| 184 | + ) |
|
| 185 | + ); |
|
| 186 | + } |
|
| 187 | + } else { |
|
| 188 | + wp_send_json_error( |
|
| 189 | + array( |
|
| 190 | + 'message' => __( 'Failed to Update Recipe Ingredient.', 'wordlift' ), |
|
| 191 | + 'btnText' => __( 'Failed!', 'wordlift' ), |
|
| 192 | + ) |
|
| 193 | + ); |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Enqueue Scripts. |
|
| 199 | + */ |
|
| 200 | + public function enqueue_scripts() { |
|
| 201 | + wp_enqueue_script( 'wl-meta-box-ingredient', WL_DIR_URL . 'js/dist/ingredients-meta-box.js', array( 'jquery', 'jquery-ui-autocomplete' ), WORDLIFT_VERSION, true ); |
|
| 202 | + |
|
| 203 | + wp_localize_script( |
|
| 204 | + 'wl-meta-box-ingredient', |
|
| 205 | + '_wlRecipeIngredient', |
|
| 206 | + array( |
|
| 207 | + 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
| 208 | + 'nonce' => wp_create_nonce( 'wl-ingredient-nonce' ), |
|
| 209 | + 'acNonce' => wp_create_nonce( 'wl-ac-ingredient-nonce' ), |
|
| 210 | + 'texts' => array( |
|
| 211 | + 'saving' => __( 'Saving...', 'wordlift' ), |
|
| 212 | + 'noResults' => __( 'No results found.', 'wordlift' ), |
|
| 213 | + ), |
|
| 214 | + ) |
|
| 215 | + ); |
|
| 216 | + } |
|
| 217 | 217 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * @param Api_Service_Ext $api_service |
| 26 | 26 | * @param Recipe_Lift_Strategy $recipe_lift_strategy |
| 27 | 27 | */ |
| 28 | - public function __construct( Api_Service_Ext $api_service, Recipe_Lift_Strategy $recipe_lift_strategy ) { |
|
| 28 | + public function __construct(Api_Service_Ext $api_service, Recipe_Lift_Strategy $recipe_lift_strategy) { |
|
| 29 | 29 | $this->api_service = $api_service; |
| 30 | 30 | $this->recipe_lift_strategy = $recipe_lift_strategy; |
| 31 | 31 | } |
@@ -36,9 +36,9 @@ discard block |
||
| 36 | 36 | * @return void |
| 37 | 37 | */ |
| 38 | 38 | public function register_hooks() { |
| 39 | - add_action( 'wl_ingredient_metabox_html', array( $this, 'ingredients_html' ) ); |
|
| 40 | - add_action( 'wp_ajax_wl_update_ingredient_post_meta', array( $this, 'update_ingredient_post_meta' ) ); |
|
| 41 | - add_action( 'wp_ajax_wl_ingredient_autocomplete', array( $this, 'wl_ingredient_autocomplete' ) ); |
|
| 39 | + add_action('wl_ingredient_metabox_html', array($this, 'ingredients_html')); |
|
| 40 | + add_action('wp_ajax_wl_update_ingredient_post_meta', array($this, 'update_ingredient_post_meta')); |
|
| 41 | + add_action('wp_ajax_wl_ingredient_autocomplete', array($this, 'wl_ingredient_autocomplete')); |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -49,17 +49,17 @@ discard block |
||
| 49 | 49 | // Enqueue scripts. |
| 50 | 50 | $this->enqueue_scripts(); |
| 51 | 51 | |
| 52 | - $recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post( get_the_ID() ); |
|
| 53 | - if ( empty( $recipe_ids ) ) { |
|
| 52 | + $recipe_ids = \WPRM_Recipe_Manager::get_recipe_ids_from_post(get_the_ID()); |
|
| 53 | + if (empty($recipe_ids)) { |
|
| 54 | 54 | return; |
| 55 | 55 | } |
| 56 | - foreach ( $recipe_ids as $key => $recipe_id ) { |
|
| 57 | - $recipe_json_ld = get_post_meta( $recipe_id, '_wl_main_ingredient_jsonld', true ); |
|
| 58 | - if ( ! $recipe_json_ld ) { |
|
| 56 | + foreach ($recipe_ids as $key => $recipe_id) { |
|
| 57 | + $recipe_json_ld = get_post_meta($recipe_id, '_wl_main_ingredient_jsonld', true); |
|
| 58 | + if ( ! $recipe_json_ld) { |
|
| 59 | 59 | continue; |
| 60 | 60 | } |
| 61 | - $recipe = json_decode( $recipe_json_ld, true ); |
|
| 62 | - if ( ! isset( $recipe['name'] ) ) { |
|
| 61 | + $recipe = json_decode($recipe_json_ld, true); |
|
| 62 | + if ( ! isset($recipe['name'])) { |
|
| 63 | 63 | continue; |
| 64 | 64 | } |
| 65 | 65 | ?> |
@@ -70,15 +70,15 @@ discard block |
||
| 70 | 70 | 'strong' => array(), |
| 71 | 71 | ); |
| 72 | 72 | // translators: %s is the ingredient name. |
| 73 | - echo wp_kses( sprintf( '<p>' . __( 'The main ingredient is', 'wordlift' ) . ' <strong>%s</strong></p>', esc_html( $recipe['name'] ) ), $allowed_tags ); |
|
| 73 | + echo wp_kses(sprintf('<p>'.__('The main ingredient is', 'wordlift').' <strong>%s</strong></p>', esc_html($recipe['name'])), $allowed_tags); |
|
| 74 | 74 | ?> |
| 75 | - <form class="wl-recipe-ingredient-form" id="wl-recipe-ingredient-form-<?php echo esc_attr( $key ); ?>"> |
|
| 75 | + <form class="wl-recipe-ingredient-form" id="wl-recipe-ingredient-form-<?php echo esc_attr($key); ?>"> |
|
| 76 | 76 | <div class="wl-recipe-ingredient__field"> |
| 77 | - <label for="wl-recipe-ingredient__field-<?php echo esc_attr( $recipe['name'] ) . '-' . esc_attr( $key ); ?>"><?php echo esc_html__( 'Replace the main ingredient', 'wordlift' ); ?>: </label> |
|
| 78 | - <input type="text" class="main-ingredient" id="wl-recipe-ingredient__field-<?php echo esc_attr( $recipe['name'] ) . '-' . esc_attr( $key ); ?>" name="main_ingredient" placeholder="<?php echo esc_html__( 'Type at least 3 characters to search...', 'wordlift' ); ?>"> |
|
| 77 | + <label for="wl-recipe-ingredient__field-<?php echo esc_attr($recipe['name']).'-'.esc_attr($key); ?>"><?php echo esc_html__('Replace the main ingredient', 'wordlift'); ?>: </label> |
|
| 78 | + <input type="text" class="main-ingredient" id="wl-recipe-ingredient__field-<?php echo esc_attr($recipe['name']).'-'.esc_attr($key); ?>" name="main_ingredient" placeholder="<?php echo esc_html__('Type at least 3 characters to search...', 'wordlift'); ?>"> |
|
| 79 | 79 | </div> |
| 80 | - <input type="hidden" id="recipe_id" name="recipe_id" value="<?php echo esc_attr( $recipe_id ); ?>"> |
|
| 81 | - <button type="submit" class="wl-recipe-ingredient__save"><?php echo esc_html__( 'Save', 'wordlift' ); ?></button> |
|
| 80 | + <input type="hidden" id="recipe_id" name="recipe_id" value="<?php echo esc_attr($recipe_id); ?>"> |
|
| 81 | + <button type="submit" class="wl-recipe-ingredient__save"><?php echo esc_html__('Save', 'wordlift'); ?></button> |
|
| 82 | 82 | </form> |
| 83 | 83 | </div> |
| 84 | 84 | <?php |
@@ -90,33 +90,33 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | public function wl_ingredient_autocomplete() { |
| 92 | 92 | |
| 93 | - check_ajax_referer( 'wl-ac-ingredient-nonce' ); |
|
| 93 | + check_ajax_referer('wl-ac-ingredient-nonce'); |
|
| 94 | 94 | |
| 95 | 95 | // Return error if the query param is empty. |
| 96 | - if ( ! empty( $_REQUEST['query'] ) ) { // Input var okay. |
|
| 97 | - $query = sanitize_text_field( wp_unslash( $_REQUEST['query'] ) ); // Input var okay. |
|
| 96 | + if ( ! empty($_REQUEST['query'])) { // Input var okay. |
|
| 97 | + $query = sanitize_text_field(wp_unslash($_REQUEST['query'])); // Input var okay. |
|
| 98 | 98 | } else { |
| 99 | 99 | wp_send_json_error( |
| 100 | 100 | array( |
| 101 | - 'message' => __( 'The query param is empty.', 'wordlift' ), |
|
| 101 | + 'message' => __('The query param is empty.', 'wordlift'), |
|
| 102 | 102 | ) |
| 103 | 103 | ); |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | // Get new JSON LD Data. |
| 107 | - $new_json_ld = $this->recipe_lift_strategy->get_json_ld_data( $query ); |
|
| 107 | + $new_json_ld = $this->recipe_lift_strategy->get_json_ld_data($query); |
|
| 108 | 108 | |
| 109 | - $data = json_decode( $new_json_ld ); |
|
| 109 | + $data = json_decode($new_json_ld); |
|
| 110 | 110 | |
| 111 | 111 | // Clear any buffer. |
| 112 | 112 | ob_clean(); |
| 113 | 113 | |
| 114 | - if ( $data ) { |
|
| 115 | - wp_send_json_success( array( $data->name ) ); |
|
| 114 | + if ($data) { |
|
| 115 | + wp_send_json_success(array($data->name)); |
|
| 116 | 116 | } else { |
| 117 | 117 | wp_send_json_error( |
| 118 | 118 | array( |
| 119 | - 'message' => __( 'No results found.', 'wordlift' ), |
|
| 119 | + 'message' => __('No results found.', 'wordlift'), |
|
| 120 | 120 | ) |
| 121 | 121 | ); |
| 122 | 122 | } |
@@ -126,69 +126,69 @@ discard block |
||
| 126 | 126 | * Update Ingredient Post Meta. |
| 127 | 127 | */ |
| 128 | 128 | public function update_ingredient_post_meta() { |
| 129 | - check_ajax_referer( 'wl-ingredient-nonce' ); |
|
| 129 | + check_ajax_referer('wl-ingredient-nonce'); |
|
| 130 | 130 | |
| 131 | 131 | // Check if current user can edit posts. |
| 132 | - if ( ! current_user_can( 'edit_posts' ) ) { |
|
| 132 | + if ( ! current_user_can('edit_posts')) { |
|
| 133 | 133 | wp_send_json_error( |
| 134 | 134 | array( |
| 135 | - 'message' => __( 'You are not allowed to edit posts.', 'wordlift' ), |
|
| 136 | - 'btnText' => __( 'Denied!', 'wordlift' ), |
|
| 135 | + 'message' => __('You are not allowed to edit posts.', 'wordlift'), |
|
| 136 | + 'btnText' => __('Denied!', 'wordlift'), |
|
| 137 | 137 | ) |
| 138 | 138 | ); |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | // Return error if the recipe id is empty. |
| 142 | - if ( ! empty( $_REQUEST['recipe_id'] ) ) { // Input var okay. |
|
| 143 | - $recipe_id = sanitize_text_field( wp_unslash( $_REQUEST['recipe_id'] ) ); // Input var okay. |
|
| 142 | + if ( ! empty($_REQUEST['recipe_id'])) { // Input var okay. |
|
| 143 | + $recipe_id = sanitize_text_field(wp_unslash($_REQUEST['recipe_id'])); // Input var okay. |
|
| 144 | 144 | } else { |
| 145 | 145 | wp_send_json_error( |
| 146 | 146 | array( |
| 147 | - 'message' => __( 'The recipe id is empty.', 'wordlift' ), |
|
| 148 | - 'btnText' => __( 'Failed!', 'wordlift' ), |
|
| 147 | + 'message' => __('The recipe id is empty.', 'wordlift'), |
|
| 148 | + 'btnText' => __('Failed!', 'wordlift'), |
|
| 149 | 149 | ) |
| 150 | 150 | ); |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | // Return error if the main ingredient is empty. |
| 154 | - if ( ! empty( $_REQUEST['main_ingredient'] ) ) { |
|
| 155 | - $main_ingredient = sanitize_text_field( wp_unslash( $_REQUEST['main_ingredient'] ) ); |
|
| 154 | + if ( ! empty($_REQUEST['main_ingredient'])) { |
|
| 155 | + $main_ingredient = sanitize_text_field(wp_unslash($_REQUEST['main_ingredient'])); |
|
| 156 | 156 | } else { |
| 157 | 157 | wp_send_json_error( |
| 158 | 158 | array( |
| 159 | - 'message' => __( 'The main ingredient is empty.', 'wordlift' ), |
|
| 160 | - 'btnText' => __( 'Failed!', 'wordlift' ), |
|
| 159 | + 'message' => __('The main ingredient is empty.', 'wordlift'), |
|
| 160 | + 'btnText' => __('Failed!', 'wordlift'), |
|
| 161 | 161 | ) |
| 162 | 162 | ); |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // Get new JSON LD Data. |
| 166 | - $new_json_ld = $this->recipe_lift_strategy->get_json_ld_data( $main_ingredient ); |
|
| 166 | + $new_json_ld = $this->recipe_lift_strategy->get_json_ld_data($main_ingredient); |
|
| 167 | 167 | |
| 168 | - if ( $new_json_ld ) { |
|
| 168 | + if ($new_json_ld) { |
|
| 169 | 169 | // Update the recipe post meta for JSON-LD. |
| 170 | - $update = update_post_meta( $recipe_id, '_wl_main_ingredient_jsonld', $new_json_ld ); |
|
| 171 | - if ( $update ) { |
|
| 170 | + $update = update_post_meta($recipe_id, '_wl_main_ingredient_jsonld', $new_json_ld); |
|
| 171 | + if ($update) { |
|
| 172 | 172 | wp_send_json_success( |
| 173 | 173 | array( |
| 174 | - 'message' => __( 'The main ingredient has been updated.', 'wordlift' ), |
|
| 175 | - 'btnText' => __( 'Saved!', 'wordlift' ), |
|
| 174 | + 'message' => __('The main ingredient has been updated.', 'wordlift'), |
|
| 175 | + 'btnText' => __('Saved!', 'wordlift'), |
|
| 176 | 176 | ) |
| 177 | 177 | ); |
| 178 | 178 | } else { |
| 179 | 179 | wp_send_json( |
| 180 | 180 | array( |
| 181 | 181 | 'same' => true, |
| 182 | - 'message' => __( 'You didn\'t updated the main ingredient value.', 'wordlift' ), |
|
| 183 | - 'btnText' => __( 'Save', 'wordlift' ), |
|
| 182 | + 'message' => __('You didn\'t updated the main ingredient value.', 'wordlift'), |
|
| 183 | + 'btnText' => __('Save', 'wordlift'), |
|
| 184 | 184 | ) |
| 185 | 185 | ); |
| 186 | 186 | } |
| 187 | 187 | } else { |
| 188 | 188 | wp_send_json_error( |
| 189 | 189 | array( |
| 190 | - 'message' => __( 'Failed to Update Recipe Ingredient.', 'wordlift' ), |
|
| 191 | - 'btnText' => __( 'Failed!', 'wordlift' ), |
|
| 190 | + 'message' => __('Failed to Update Recipe Ingredient.', 'wordlift'), |
|
| 191 | + 'btnText' => __('Failed!', 'wordlift'), |
|
| 192 | 192 | ) |
| 193 | 193 | ); |
| 194 | 194 | } |
@@ -198,18 +198,18 @@ discard block |
||
| 198 | 198 | * Enqueue Scripts. |
| 199 | 199 | */ |
| 200 | 200 | public function enqueue_scripts() { |
| 201 | - wp_enqueue_script( 'wl-meta-box-ingredient', WL_DIR_URL . 'js/dist/ingredients-meta-box.js', array( 'jquery', 'jquery-ui-autocomplete' ), WORDLIFT_VERSION, true ); |
|
| 201 | + wp_enqueue_script('wl-meta-box-ingredient', WL_DIR_URL.'js/dist/ingredients-meta-box.js', array('jquery', 'jquery-ui-autocomplete'), WORDLIFT_VERSION, true); |
|
| 202 | 202 | |
| 203 | 203 | wp_localize_script( |
| 204 | 204 | 'wl-meta-box-ingredient', |
| 205 | 205 | '_wlRecipeIngredient', |
| 206 | 206 | array( |
| 207 | - 'ajaxurl' => admin_url( 'admin-ajax.php' ), |
|
| 208 | - 'nonce' => wp_create_nonce( 'wl-ingredient-nonce' ), |
|
| 209 | - 'acNonce' => wp_create_nonce( 'wl-ac-ingredient-nonce' ), |
|
| 207 | + 'ajaxurl' => admin_url('admin-ajax.php'), |
|
| 208 | + 'nonce' => wp_create_nonce('wl-ingredient-nonce'), |
|
| 209 | + 'acNonce' => wp_create_nonce('wl-ac-ingredient-nonce'), |
|
| 210 | 210 | 'texts' => array( |
| 211 | - 'saving' => __( 'Saving...', 'wordlift' ), |
|
| 212 | - 'noResults' => __( 'No results found.', 'wordlift' ), |
|
| 211 | + 'saving' => __('Saving...', 'wordlift'), |
|
| 212 | + 'noResults' => __('No results found.', 'wordlift'), |
|
| 213 | 213 | ), |
| 214 | 214 | ) |
| 215 | 215 | ); |
@@ -6,79 +6,79 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Import_Page extends Wordlift_Admin_Page { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * {@inheritdoc} |
|
| 11 | - */ |
|
| 12 | - public function get_page_title() { |
|
| 13 | - |
|
| 14 | - return __( 'Google Addon Import', 'wordlift' ); |
|
| 15 | - } |
|
| 16 | - |
|
| 17 | - /** |
|
| 18 | - * {@inheritdoc} |
|
| 19 | - */ |
|
| 20 | - public function get_menu_title() { |
|
| 21 | - |
|
| 22 | - return __( 'Google Addon Import', 'wordlift' ); |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - protected function get_parent_slug() { |
|
| 26 | - return null; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - public function render() { |
|
| 30 | - |
|
| 31 | - wp_enqueue_script( |
|
| 32 | - 'wl-gaddon-import-page', |
|
| 33 | - plugin_dir_url( __FILE__ ) . 'assets/gaddon-import-page.js', |
|
| 34 | - array(), |
|
| 35 | - WORDLIFT_VERSION, |
|
| 36 | - false |
|
| 37 | - ); |
|
| 38 | - |
|
| 39 | - wp_localize_script( |
|
| 40 | - 'wl-gaddon-import-page', |
|
| 41 | - '_wlGaddonImportSettings', |
|
| 42 | - array( |
|
| 43 | - 'restUrl' => get_rest_url(), |
|
| 44 | - 'nonce' => wp_create_nonce( 'wp_rest' ), |
|
| 45 | - 'entityUrls' => $this->get_entity_urls(), |
|
| 46 | - ) |
|
| 47 | - ); |
|
| 48 | - |
|
| 49 | - parent::render(); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * {@inheritdoc} |
|
| 54 | - */ |
|
| 55 | - public function get_menu_slug() { |
|
| 56 | - |
|
| 57 | - return 'wl_google_addon_import'; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * {@inheritdoc} |
|
| 62 | - */ |
|
| 63 | - public function get_partial_name() { |
|
| 64 | - return 'wordlift-admin-google-addon-import.php'; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - private function get_entity_urls() { |
|
| 68 | - if ( ! isset( $_GET['e'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 69 | - return array(); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - $entities = esc_url_raw( wp_unslash( $_GET['e'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 73 | - |
|
| 74 | - if ( empty( $entities ) ) { |
|
| 75 | - return array(); |
|
| 76 | - } |
|
| 77 | - if ( ! is_string( $entities ) ) { |
|
| 78 | - return array(); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - return explode( ',', $entities ); |
|
| 82 | - } |
|
| 9 | + /** |
|
| 10 | + * {@inheritdoc} |
|
| 11 | + */ |
|
| 12 | + public function get_page_title() { |
|
| 13 | + |
|
| 14 | + return __( 'Google Addon Import', 'wordlift' ); |
|
| 15 | + } |
|
| 16 | + |
|
| 17 | + /** |
|
| 18 | + * {@inheritdoc} |
|
| 19 | + */ |
|
| 20 | + public function get_menu_title() { |
|
| 21 | + |
|
| 22 | + return __( 'Google Addon Import', 'wordlift' ); |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + protected function get_parent_slug() { |
|
| 26 | + return null; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + public function render() { |
|
| 30 | + |
|
| 31 | + wp_enqueue_script( |
|
| 32 | + 'wl-gaddon-import-page', |
|
| 33 | + plugin_dir_url( __FILE__ ) . 'assets/gaddon-import-page.js', |
|
| 34 | + array(), |
|
| 35 | + WORDLIFT_VERSION, |
|
| 36 | + false |
|
| 37 | + ); |
|
| 38 | + |
|
| 39 | + wp_localize_script( |
|
| 40 | + 'wl-gaddon-import-page', |
|
| 41 | + '_wlGaddonImportSettings', |
|
| 42 | + array( |
|
| 43 | + 'restUrl' => get_rest_url(), |
|
| 44 | + 'nonce' => wp_create_nonce( 'wp_rest' ), |
|
| 45 | + 'entityUrls' => $this->get_entity_urls(), |
|
| 46 | + ) |
|
| 47 | + ); |
|
| 48 | + |
|
| 49 | + parent::render(); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * {@inheritdoc} |
|
| 54 | + */ |
|
| 55 | + public function get_menu_slug() { |
|
| 56 | + |
|
| 57 | + return 'wl_google_addon_import'; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * {@inheritdoc} |
|
| 62 | + */ |
|
| 63 | + public function get_partial_name() { |
|
| 64 | + return 'wordlift-admin-google-addon-import.php'; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + private function get_entity_urls() { |
|
| 68 | + if ( ! isset( $_GET['e'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 69 | + return array(); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + $entities = esc_url_raw( wp_unslash( $_GET['e'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 73 | + |
|
| 74 | + if ( empty( $entities ) ) { |
|
| 75 | + return array(); |
|
| 76 | + } |
|
| 77 | + if ( ! is_string( $entities ) ) { |
|
| 78 | + return array(); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + return explode( ',', $entities ); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | 84 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | */ |
| 12 | 12 | public function get_page_title() { |
| 13 | 13 | |
| 14 | - return __( 'Google Addon Import', 'wordlift' ); |
|
| 14 | + return __('Google Addon Import', 'wordlift'); |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | public function get_menu_title() { |
| 21 | 21 | |
| 22 | - return __( 'Google Addon Import', 'wordlift' ); |
|
| 22 | + return __('Google Addon Import', 'wordlift'); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | protected function get_parent_slug() { |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | wp_enqueue_script( |
| 32 | 32 | 'wl-gaddon-import-page', |
| 33 | - plugin_dir_url( __FILE__ ) . 'assets/gaddon-import-page.js', |
|
| 33 | + plugin_dir_url(__FILE__).'assets/gaddon-import-page.js', |
|
| 34 | 34 | array(), |
| 35 | 35 | WORDLIFT_VERSION, |
| 36 | 36 | false |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | '_wlGaddonImportSettings', |
| 42 | 42 | array( |
| 43 | 43 | 'restUrl' => get_rest_url(), |
| 44 | - 'nonce' => wp_create_nonce( 'wp_rest' ), |
|
| 44 | + 'nonce' => wp_create_nonce('wp_rest'), |
|
| 45 | 45 | 'entityUrls' => $this->get_entity_urls(), |
| 46 | 46 | ) |
| 47 | 47 | ); |
@@ -65,20 +65,20 @@ discard block |
||
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | private function get_entity_urls() { |
| 68 | - if ( ! isset( $_GET['e'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 68 | + if ( ! isset($_GET['e'])) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 69 | 69 | return array(); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - $entities = esc_url_raw( wp_unslash( $_GET['e'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 72 | + $entities = esc_url_raw(wp_unslash($_GET['e'])); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 73 | 73 | |
| 74 | - if ( empty( $entities ) ) { |
|
| 74 | + if (empty($entities)) { |
|
| 75 | 75 | return array(); |
| 76 | 76 | } |
| 77 | - if ( ! is_string( $entities ) ) { |
|
| 77 | + if ( ! is_string($entities)) { |
|
| 78 | 78 | return array(); |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - return explode( ',', $entities ); |
|
| 81 | + return explode(',', $entities); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | } |
@@ -1,4 +1,4 @@ |
||
| 1 | 1 | <?php return array( |
| 2 | - 'dependencies' => array( 'wp-polyfill' ), |
|
| 3 | - 'version' => 'b0a070e1be01702ea526968d491a01ed', |
|
| 2 | + 'dependencies' => array( 'wp-polyfill' ), |
|
| 3 | + 'version' => 'b0a070e1be01702ea526968d491a01ed', |
|
| 4 | 4 | ); |
@@ -1,4 +1,4 @@ |
||
| 1 | 1 | <?php return array( |
| 2 | - 'dependencies' => array( 'wp-polyfill' ), |
|
| 2 | + 'dependencies' => array('wp-polyfill'), |
|
| 3 | 3 | 'version' => 'b0a070e1be01702ea526968d491a01ed', |
| 4 | 4 | ); |
@@ -17,16 +17,16 @@ discard block |
||
| 17 | 17 | use Wordlift\Modules\Pods\WlEntityField\Filters; |
| 18 | 18 | |
| 19 | 19 | if ( ! defined( 'ABSPATH' ) ) { |
| 20 | - exit; |
|
| 20 | + exit; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if ( ! apply_filters( 'wl_feature__enable__pods-integration', false ) ) { //phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
| 24 | - return; |
|
| 24 | + return; |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | // Autoloader for plugin itself. |
| 28 | 28 | if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { |
| 29 | - require __DIR__ . '/vendor/autoload.php'; |
|
| 29 | + require __DIR__ . '/vendor/autoload.php'; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | $container_builder = new ContainerBuilder(); |
@@ -35,32 +35,32 @@ discard block |
||
| 35 | 35 | $container_builder->compile(); |
| 36 | 36 | |
| 37 | 37 | add_action( |
| 38 | - 'plugins_loaded', |
|
| 39 | - function () use ( $container_builder ) { |
|
| 38 | + 'plugins_loaded', |
|
| 39 | + function () use ( $container_builder ) { |
|
| 40 | 40 | |
| 41 | - if ( ! defined( 'PODS_VERSION' ) ) { |
|
| 42 | - return; |
|
| 43 | - } |
|
| 41 | + if ( ! defined( 'PODS_VERSION' ) ) { |
|
| 42 | + return; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - $factory = $container_builder->get( FieldDefinitionFactory::class ); |
|
| 46 | - $field_definition = $factory->get_field_definition(); |
|
| 47 | - $field_definition->register(); |
|
| 45 | + $factory = $container_builder->get( FieldDefinitionFactory::class ); |
|
| 46 | + $field_definition = $factory->get_field_definition(); |
|
| 47 | + $field_definition->register(); |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @var $installer \Wordlift\Modules\Pods\Installer |
|
| 51 | - */ |
|
| 52 | - $installer = $container_builder->get( Installer::class ); |
|
| 53 | - $installer->register_hooks(); |
|
| 49 | + /** |
|
| 50 | + * @var $installer \Wordlift\Modules\Pods\Installer |
|
| 51 | + */ |
|
| 52 | + $installer = $container_builder->get( Installer::class ); |
|
| 53 | + $installer->register_hooks(); |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @var $notices \Wordlift\Modules\Pods\Notices |
|
| 57 | - */ |
|
| 58 | - $notices = $container_builder->get( Notices::class ); |
|
| 59 | - $notices->register_hooks(); |
|
| 55 | + /** |
|
| 56 | + * @var $notices \Wordlift\Modules\Pods\Notices |
|
| 57 | + */ |
|
| 58 | + $notices = $container_builder->get( Notices::class ); |
|
| 59 | + $notices->register_hooks(); |
|
| 60 | 60 | |
| 61 | - $container_builder->get( Filters::class ); |
|
| 61 | + $container_builder->get( Filters::class ); |
|
| 62 | 62 | |
| 63 | - } |
|
| 63 | + } |
|
| 64 | 64 | ); |
| 65 | 65 | |
| 66 | 66 | |
@@ -16,49 +16,49 @@ |
||
| 16 | 16 | use Wordlift\Modules\Pods\Notices; |
| 17 | 17 | use Wordlift\Modules\Pods\WlEntityField\Filters; |
| 18 | 18 | |
| 19 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 19 | +if ( ! defined('ABSPATH')) { |
|
| 20 | 20 | exit; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | -if ( ! apply_filters( 'wl_feature__enable__pods-integration', false ) ) { //phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
| 23 | +if ( ! apply_filters('wl_feature__enable__pods-integration', false)) { //phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
| 24 | 24 | return; |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | // Autoloader for plugin itself. |
| 28 | -if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) { |
|
| 29 | - require __DIR__ . '/vendor/autoload.php'; |
|
| 28 | +if (file_exists(__DIR__.'/vendor/autoload.php')) { |
|
| 29 | + require __DIR__.'/vendor/autoload.php'; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | $container_builder = new ContainerBuilder(); |
| 33 | -$loader = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) ); |
|
| 34 | -$loader->load( 'services.yml' ); |
|
| 33 | +$loader = new YamlFileLoader($container_builder, new FileLocator(__DIR__)); |
|
| 34 | +$loader->load('services.yml'); |
|
| 35 | 35 | $container_builder->compile(); |
| 36 | 36 | |
| 37 | 37 | add_action( |
| 38 | 38 | 'plugins_loaded', |
| 39 | - function () use ( $container_builder ) { |
|
| 39 | + function() use ($container_builder) { |
|
| 40 | 40 | |
| 41 | - if ( ! defined( 'PODS_VERSION' ) ) { |
|
| 41 | + if ( ! defined('PODS_VERSION')) { |
|
| 42 | 42 | return; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - $factory = $container_builder->get( FieldDefinitionFactory::class ); |
|
| 45 | + $factory = $container_builder->get(FieldDefinitionFactory::class); |
|
| 46 | 46 | $field_definition = $factory->get_field_definition(); |
| 47 | 47 | $field_definition->register(); |
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * @var $installer \Wordlift\Modules\Pods\Installer |
| 51 | 51 | */ |
| 52 | - $installer = $container_builder->get( Installer::class ); |
|
| 52 | + $installer = $container_builder->get(Installer::class); |
|
| 53 | 53 | $installer->register_hooks(); |
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * @var $notices \Wordlift\Modules\Pods\Notices |
| 57 | 57 | */ |
| 58 | - $notices = $container_builder->get( Notices::class ); |
|
| 58 | + $notices = $container_builder->get(Notices::class); |
|
| 59 | 59 | $notices->register_hooks(); |
| 60 | 60 | |
| 61 | - $container_builder->get( Filters::class ); |
|
| 61 | + $container_builder->get(Filters::class); |
|
| 62 | 62 | |
| 63 | 63 | } |
| 64 | 64 | ); |
@@ -21,45 +21,45 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class Jsonld_Adapter { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var Wordlift_Jsonld_Service |
|
| 26 | - */ |
|
| 27 | - private $jsonld_service; |
|
| 24 | + /** |
|
| 25 | + * @var Wordlift_Jsonld_Service |
|
| 26 | + */ |
|
| 27 | + private $jsonld_service; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Jsonld_Adapter constructor. |
|
| 31 | - * |
|
| 32 | - * @param \Wordlift_Jsonld_Service $jsonld_service |
|
| 33 | - */ |
|
| 34 | - public function __construct( $jsonld_service ) { |
|
| 29 | + /** |
|
| 30 | + * Jsonld_Adapter constructor. |
|
| 31 | + * |
|
| 32 | + * @param \Wordlift_Jsonld_Service $jsonld_service |
|
| 33 | + */ |
|
| 34 | + public function __construct( $jsonld_service ) { |
|
| 35 | 35 | |
| 36 | - $this->jsonld_service = $jsonld_service; |
|
| 36 | + $this->jsonld_service = $jsonld_service; |
|
| 37 | 37 | |
| 38 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
| 39 | - add_action( 'amp_post_template_head', array( $this, 'wp_head' ) ); |
|
| 38 | + add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
| 39 | + add_action( 'amp_post_template_head', array( $this, 'wp_head' ) ); |
|
| 40 | 40 | |
| 41 | - } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - public function wp_head() { |
|
| 43 | + public function wp_head() { |
|
| 44 | 44 | |
| 45 | - // Bail out if `wl_jsonld_enabled` isn't enabled. |
|
| 46 | - if ( ! apply_filters( 'wl_jsonld_enabled', true ) ) { |
|
| 47 | - return; |
|
| 48 | - } |
|
| 45 | + // Bail out if `wl_jsonld_enabled` isn't enabled. |
|
| 46 | + if ( ! apply_filters( 'wl_jsonld_enabled', true ) ) { |
|
| 47 | + return; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - // Determine whether this is the home page or whether we're displaying a single post. |
|
| 51 | - $is_homepage = is_home() || is_front_page(); |
|
| 52 | - $post_id = is_singular() ? get_the_ID() : null; |
|
| 50 | + // Determine whether this is the home page or whether we're displaying a single post. |
|
| 51 | + $is_homepage = is_home() || is_front_page(); |
|
| 52 | + $post_id = is_singular() ? get_the_ID() : null; |
|
| 53 | 53 | |
| 54 | - // Get the JSON-LD. |
|
| 55 | - $jsonld = wp_json_encode( $this->jsonld_service->get_jsonld( $is_homepage, $post_id, Jsonld_Context_Enum::PAGE ) ); |
|
| 56 | - // Finally print the JSON-LD out. |
|
| 57 | - $jsonld_post_html_output = '<script type="application/ld+json" id="wl-jsonld">' . $jsonld . '</script>'; |
|
| 58 | - $jsonld_post_html_output = apply_filters( 'wl_jsonld_post_html_output', $jsonld_post_html_output, $post_id ); |
|
| 54 | + // Get the JSON-LD. |
|
| 55 | + $jsonld = wp_json_encode( $this->jsonld_service->get_jsonld( $is_homepage, $post_id, Jsonld_Context_Enum::PAGE ) ); |
|
| 56 | + // Finally print the JSON-LD out. |
|
| 57 | + $jsonld_post_html_output = '<script type="application/ld+json" id="wl-jsonld">' . $jsonld . '</script>'; |
|
| 58 | + $jsonld_post_html_output = apply_filters( 'wl_jsonld_post_html_output', $jsonld_post_html_output, $post_id ); |
|
| 59 | 59 | |
| 60 | - // We don't need to escape this one since it's a JSON-LD output. |
|
| 61 | - echo $jsonld_post_html_output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
| 60 | + // We don't need to escape this one since it's a JSON-LD output. |
|
| 61 | + echo $jsonld_post_html_output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
| 62 | 62 | |
| 63 | - } |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | 65 | } |
@@ -31,19 +31,19 @@ discard block |
||
| 31 | 31 | * |
| 32 | 32 | * @param \Wordlift_Jsonld_Service $jsonld_service |
| 33 | 33 | */ |
| 34 | - public function __construct( $jsonld_service ) { |
|
| 34 | + public function __construct($jsonld_service) { |
|
| 35 | 35 | |
| 36 | 36 | $this->jsonld_service = $jsonld_service; |
| 37 | 37 | |
| 38 | - add_action( 'wp_head', array( $this, 'wp_head' ) ); |
|
| 39 | - add_action( 'amp_post_template_head', array( $this, 'wp_head' ) ); |
|
| 38 | + add_action('wp_head', array($this, 'wp_head')); |
|
| 39 | + add_action('amp_post_template_head', array($this, 'wp_head')); |
|
| 40 | 40 | |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | public function wp_head() { |
| 44 | 44 | |
| 45 | 45 | // Bail out if `wl_jsonld_enabled` isn't enabled. |
| 46 | - if ( ! apply_filters( 'wl_jsonld_enabled', true ) ) { |
|
| 46 | + if ( ! apply_filters('wl_jsonld_enabled', true)) { |
|
| 47 | 47 | return; |
| 48 | 48 | } |
| 49 | 49 | |
@@ -52,10 +52,10 @@ discard block |
||
| 52 | 52 | $post_id = is_singular() ? get_the_ID() : null; |
| 53 | 53 | |
| 54 | 54 | // Get the JSON-LD. |
| 55 | - $jsonld = wp_json_encode( $this->jsonld_service->get_jsonld( $is_homepage, $post_id, Jsonld_Context_Enum::PAGE ) ); |
|
| 55 | + $jsonld = wp_json_encode($this->jsonld_service->get_jsonld($is_homepage, $post_id, Jsonld_Context_Enum::PAGE)); |
|
| 56 | 56 | // Finally print the JSON-LD out. |
| 57 | - $jsonld_post_html_output = '<script type="application/ld+json" id="wl-jsonld">' . $jsonld . '</script>'; |
|
| 58 | - $jsonld_post_html_output = apply_filters( 'wl_jsonld_post_html_output', $jsonld_post_html_output, $post_id ); |
|
| 57 | + $jsonld_post_html_output = '<script type="application/ld+json" id="wl-jsonld">'.$jsonld.'</script>'; |
|
| 58 | + $jsonld_post_html_output = apply_filters('wl_jsonld_post_html_output', $jsonld_post_html_output, $post_id); |
|
| 59 | 59 | |
| 60 | 60 | // We don't need to escape this one since it's a JSON-LD output. |
| 61 | 61 | echo $jsonld_post_html_output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
@@ -16,87 +16,87 @@ discard block |
||
| 16 | 16 | * @subpackage Wordlift/admin/WL_Metabox |
| 17 | 17 | */ |
| 18 | 18 | class Wl_Abstract_Metabox { |
| 19 | - /** |
|
| 20 | - * The metabox custom fields for the current {@link WP_Post}. |
|
| 21 | - * |
|
| 22 | - * @since 3.1.0 |
|
| 23 | - * @access public |
|
| 24 | - * @var array $fields The metabox custom fields. |
|
| 25 | - */ |
|
| 26 | - public $fields; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * A {@link Wordlift_Log_Service} instance. |
|
| 30 | - * |
|
| 31 | - * @since 3.15.4 |
|
| 32 | - * |
|
| 33 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 34 | - */ |
|
| 35 | - private $log; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * WL_Metabox constructor. |
|
| 39 | - * |
|
| 40 | - * @since 3.1.0 |
|
| 41 | - */ |
|
| 42 | - public function __construct() { |
|
| 43 | - |
|
| 44 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Add a callback to print the metabox in page. |
|
| 49 | - * WordPress will fire the $this->html() callback at the right time. |
|
| 50 | - */ |
|
| 51 | - public function add_main_metabox() { |
|
| 52 | - |
|
| 53 | - // Build the fields we need to print. |
|
| 54 | - $this->instantiate_fields( get_the_ID(), Object_Type_Enum::POST ); |
|
| 55 | - |
|
| 56 | - // Bailout if there are no actual fields, we do not need a metabox in that case. |
|
| 57 | - if ( empty( $this->fields ) ) { |
|
| 58 | - return; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - // Add main metabox (will print also the inner fields). |
|
| 62 | - $id = uniqid( 'wl-metabox-' ); |
|
| 63 | - $title = __( 'WordLift', 'wordlift' ); |
|
| 64 | - |
|
| 65 | - // WordPress 4.2 do not accept an array of screens as parameter, have to do be explicit. |
|
| 66 | - foreach ( Wordlift_Entity_Service::valid_entity_post_types() as $screen ) { |
|
| 67 | - add_meta_box( |
|
| 68 | - $id, |
|
| 69 | - esc_html( $title ), |
|
| 70 | - array( |
|
| 71 | - $this, |
|
| 72 | - 'html', |
|
| 73 | - ), |
|
| 74 | - $screen, |
|
| 75 | - 'normal', |
|
| 76 | - 'high' |
|
| 77 | - ); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // Add filter to change the metabox CSS class. |
|
| 81 | - // |
|
| 82 | - // @since 3.20.0 Since we support post types other than `entity` for entities, we need to set the `screen` |
|
| 83 | - // dynamically according to the `get_current_screen()` function. |
|
| 84 | - $current_screen = get_current_screen(); |
|
| 85 | - $screen = $current_screen ? $current_screen->post_type : 'entity'; |
|
| 86 | - add_filter( "postbox_classes_{$screen}_$id", 'wl_admin_metaboxes_add_css_class' ); |
|
| 87 | - |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Render the metabox html. |
|
| 92 | - * |
|
| 93 | - * @since 3.1.0 |
|
| 94 | - */ |
|
| 95 | - public function html() { |
|
| 96 | - |
|
| 97 | - // HTML Code Before MetaBox Content. |
|
| 98 | - do_action( 'wl_metabox_before_html' ); |
|
| 99 | - ?> |
|
| 19 | + /** |
|
| 20 | + * The metabox custom fields for the current {@link WP_Post}. |
|
| 21 | + * |
|
| 22 | + * @since 3.1.0 |
|
| 23 | + * @access public |
|
| 24 | + * @var array $fields The metabox custom fields. |
|
| 25 | + */ |
|
| 26 | + public $fields; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * A {@link Wordlift_Log_Service} instance. |
|
| 30 | + * |
|
| 31 | + * @since 3.15.4 |
|
| 32 | + * |
|
| 33 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 34 | + */ |
|
| 35 | + private $log; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * WL_Metabox constructor. |
|
| 39 | + * |
|
| 40 | + * @since 3.1.0 |
|
| 41 | + */ |
|
| 42 | + public function __construct() { |
|
| 43 | + |
|
| 44 | + $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Add a callback to print the metabox in page. |
|
| 49 | + * WordPress will fire the $this->html() callback at the right time. |
|
| 50 | + */ |
|
| 51 | + public function add_main_metabox() { |
|
| 52 | + |
|
| 53 | + // Build the fields we need to print. |
|
| 54 | + $this->instantiate_fields( get_the_ID(), Object_Type_Enum::POST ); |
|
| 55 | + |
|
| 56 | + // Bailout if there are no actual fields, we do not need a metabox in that case. |
|
| 57 | + if ( empty( $this->fields ) ) { |
|
| 58 | + return; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + // Add main metabox (will print also the inner fields). |
|
| 62 | + $id = uniqid( 'wl-metabox-' ); |
|
| 63 | + $title = __( 'WordLift', 'wordlift' ); |
|
| 64 | + |
|
| 65 | + // WordPress 4.2 do not accept an array of screens as parameter, have to do be explicit. |
|
| 66 | + foreach ( Wordlift_Entity_Service::valid_entity_post_types() as $screen ) { |
|
| 67 | + add_meta_box( |
|
| 68 | + $id, |
|
| 69 | + esc_html( $title ), |
|
| 70 | + array( |
|
| 71 | + $this, |
|
| 72 | + 'html', |
|
| 73 | + ), |
|
| 74 | + $screen, |
|
| 75 | + 'normal', |
|
| 76 | + 'high' |
|
| 77 | + ); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // Add filter to change the metabox CSS class. |
|
| 81 | + // |
|
| 82 | + // @since 3.20.0 Since we support post types other than `entity` for entities, we need to set the `screen` |
|
| 83 | + // dynamically according to the `get_current_screen()` function. |
|
| 84 | + $current_screen = get_current_screen(); |
|
| 85 | + $screen = $current_screen ? $current_screen->post_type : 'entity'; |
|
| 86 | + add_filter( "postbox_classes_{$screen}_$id", 'wl_admin_metaboxes_add_css_class' ); |
|
| 87 | + |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Render the metabox html. |
|
| 92 | + * |
|
| 93 | + * @since 3.1.0 |
|
| 94 | + */ |
|
| 95 | + public function html() { |
|
| 96 | + |
|
| 97 | + // HTML Code Before MetaBox Content. |
|
| 98 | + do_action( 'wl_metabox_before_html' ); |
|
| 99 | + ?> |
|
| 100 | 100 | <div class="wl-tabs"> |
| 101 | 101 | |
| 102 | 102 | <input id="wl-tab-properties" type="radio" name="wl-metabox-tabs" checked="checked"/><label |
@@ -117,8 +117,8 @@ discard block |
||
| 117 | 117 | <?php |
| 118 | 118 | // Only display the Main Ingredient tab if the feature is enabled. |
| 119 | 119 | // @@todo this tab shouldn't show if there are no ingredients. |
| 120 | - if ( apply_filters( 'wl_feature__enable__food-kg', false ) ) { |
|
| 121 | - ?> |
|
| 120 | + if ( apply_filters( 'wl_feature__enable__food-kg', false ) ) { |
|
| 121 | + ?> |
|
| 122 | 122 | <input id="wl-tab-main-ingredient" type="radio" name="wl-metabox-tabs" checked="true"/><label |
| 123 | 123 | for="wl-tab-main-ingredient"><?php esc_html_e( 'Main Ingredient', 'wordlift' ); ?></label> |
| 124 | 124 | <div class="wl-tabs__tab"> |
@@ -127,298 +127,298 @@ discard block |
||
| 127 | 127 | ?> |
| 128 | 128 | </div> |
| 129 | 129 | <?php |
| 130 | - } ?> |
|
| 130 | + } ?> |
|
| 131 | 131 | </div> |
| 132 | 132 | <?php |
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Read the WL <-> Schema mapping and build the Fields for the entity being edited. |
|
| 137 | - * |
|
| 138 | - * Note: the first function that calls this method will instantiate the fields. |
|
| 139 | - * Why it isn't called from the constructor? Because we need to hook this process as late as possible. |
|
| 140 | - * |
|
| 141 | - * @param int $id | $term_id The post id or term id. |
|
| 142 | - * |
|
| 143 | - * @param $type int Post or Term |
|
| 144 | - * |
|
| 145 | - * @since 3.1.0 |
|
| 146 | - */ |
|
| 147 | - public function instantiate_fields( $id, $type ) { |
|
| 148 | - |
|
| 149 | - $this->log->trace( "Instantiating fields for entity post $id..." ); |
|
| 150 | - |
|
| 151 | - // This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering. |
|
| 152 | - if ( isset( $this->fields ) ) { |
|
| 153 | - return; |
|
| 154 | - } |
|
| 155 | - if ( Object_Type_Enum::POST === $type ) { |
|
| 156 | - $entity_type = wl_entity_taxonomy_get_custom_fields( $id ); |
|
| 157 | - } elseif ( Object_Type_Enum::TERM === $type ) { |
|
| 158 | - $term_entity_types = get_term_meta( $id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 159 | - $term_entity_types = array_map( |
|
| 160 | - function ( $term ) { |
|
| 161 | - return get_term_by( |
|
| 162 | - 'slug', |
|
| 163 | - $term, |
|
| 164 | - Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME |
|
| 165 | - ); |
|
| 166 | - }, |
|
| 167 | - $term_entity_types |
|
| 168 | - ); |
|
| 169 | - $entity_type = wl_get_custom_fields_by_entity_type( $term_entity_types ); |
|
| 170 | - } |
|
| 171 | - if ( isset( $entity_type ) ) { |
|
| 172 | - |
|
| 173 | - /* |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Read the WL <-> Schema mapping and build the Fields for the entity being edited. |
|
| 137 | + * |
|
| 138 | + * Note: the first function that calls this method will instantiate the fields. |
|
| 139 | + * Why it isn't called from the constructor? Because we need to hook this process as late as possible. |
|
| 140 | + * |
|
| 141 | + * @param int $id | $term_id The post id or term id. |
|
| 142 | + * |
|
| 143 | + * @param $type int Post or Term |
|
| 144 | + * |
|
| 145 | + * @since 3.1.0 |
|
| 146 | + */ |
|
| 147 | + public function instantiate_fields( $id, $type ) { |
|
| 148 | + |
|
| 149 | + $this->log->trace( "Instantiating fields for entity post $id..." ); |
|
| 150 | + |
|
| 151 | + // This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering. |
|
| 152 | + if ( isset( $this->fields ) ) { |
|
| 153 | + return; |
|
| 154 | + } |
|
| 155 | + if ( Object_Type_Enum::POST === $type ) { |
|
| 156 | + $entity_type = wl_entity_taxonomy_get_custom_fields( $id ); |
|
| 157 | + } elseif ( Object_Type_Enum::TERM === $type ) { |
|
| 158 | + $term_entity_types = get_term_meta( $id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 159 | + $term_entity_types = array_map( |
|
| 160 | + function ( $term ) { |
|
| 161 | + return get_term_by( |
|
| 162 | + 'slug', |
|
| 163 | + $term, |
|
| 164 | + Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME |
|
| 165 | + ); |
|
| 166 | + }, |
|
| 167 | + $term_entity_types |
|
| 168 | + ); |
|
| 169 | + $entity_type = wl_get_custom_fields_by_entity_type( $term_entity_types ); |
|
| 170 | + } |
|
| 171 | + if ( isset( $entity_type ) ) { |
|
| 172 | + |
|
| 173 | + /* |
|
| 174 | 174 | * Might not have any relevant meta box field, for example for articles, |
| 175 | 175 | * therefor make sure fields are at least an empty array to help the considered |
| 176 | 176 | * in other functions using it. |
| 177 | 177 | */ |
| 178 | - $this->fields = array(); |
|
| 178 | + $this->fields = array(); |
|
| 179 | 179 | |
| 180 | - /** |
|
| 181 | - * In some special case, properties must be grouped in one field (e.g. coordinates) or dealed with custom methods. |
|
| 182 | - * We must divide fields in two groups: |
|
| 183 | - * - simple: accept values for one property |
|
| 184 | - * - grouped: accept values for more properties, or for one property that needs a specific metabox. |
|
| 185 | - */ |
|
| 186 | - $metaboxes = $this->group_properties_by_input_field( $entity_type ); |
|
| 187 | - $simple_metaboxes = $metaboxes[0]; |
|
| 188 | - $grouped_metaboxes = $metaboxes[1]; |
|
| 180 | + /** |
|
| 181 | + * In some special case, properties must be grouped in one field (e.g. coordinates) or dealed with custom methods. |
|
| 182 | + * We must divide fields in two groups: |
|
| 183 | + * - simple: accept values for one property |
|
| 184 | + * - grouped: accept values for more properties, or for one property that needs a specific metabox. |
|
| 185 | + */ |
|
| 186 | + $metaboxes = $this->group_properties_by_input_field( $entity_type ); |
|
| 187 | + $simple_metaboxes = $metaboxes[0]; |
|
| 188 | + $grouped_metaboxes = $metaboxes[1]; |
|
| 189 | + |
|
| 190 | + // Loop over simple entity properties. |
|
| 191 | + foreach ( $simple_metaboxes as $key => $property ) { |
|
| 192 | + |
|
| 193 | + // Info passed to the metabox. |
|
| 194 | + $info = array(); |
|
| 195 | + $info[ $key ] = $property; |
|
| 196 | + |
|
| 197 | + // Build the requested field as WL_Metabox_Field_ object. |
|
| 198 | + $this->add_field( $info, false, $type, $id ); |
|
| 199 | + |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + // Loop over grouped properties. |
|
| 203 | + foreach ( $grouped_metaboxes as $key => $property ) { |
|
| 189 | 204 | |
| 190 | - // Loop over simple entity properties. |
|
| 191 | - foreach ( $simple_metaboxes as $key => $property ) { |
|
| 205 | + // Info passed to the metabox. |
|
| 206 | + $info = array(); |
|
| 207 | + $info[ $key ] = $property; |
|
| 192 | 208 | |
| 193 | - // Info passed to the metabox. |
|
| 194 | - $info = array(); |
|
| 195 | - $info[ $key ] = $property; |
|
| 209 | + // Build the requested field group as WL_Metabox_Field_ object. |
|
| 210 | + $this->add_field( $info, true, $type, $id ); |
|
| 196 | 211 | |
| 197 | - // Build the requested field as WL_Metabox_Field_ object. |
|
| 198 | - $this->add_field( $info, false, $type, $id ); |
|
| 212 | + } |
|
| 213 | + } |
|
| 199 | 214 | |
| 200 | - } |
|
| 215 | + } |
|
| 201 | 216 | |
| 202 | - // Loop over grouped properties. |
|
| 203 | - foreach ( $grouped_metaboxes as $key => $property ) { |
|
| 217 | + /** |
|
| 218 | + * Separates metaboxes in simple and grouped. |
|
| 219 | + * |
|
| 220 | + * @param array $custom_fields Information on the entity type. |
|
| 221 | + * |
|
| 222 | + * @return array |
|
| 223 | + */ |
|
| 224 | + public function group_properties_by_input_field( $custom_fields ) { |
|
| 204 | 225 | |
| 205 | - // Info passed to the metabox. |
|
| 206 | - $info = array(); |
|
| 207 | - $info[ $key ] = $property; |
|
| 226 | + $simple_properties = array(); |
|
| 227 | + $grouped_properties = array(); |
|
| 208 | 228 | |
| 209 | - // Build the requested field group as WL_Metabox_Field_ object. |
|
| 210 | - $this->add_field( $info, true, $type, $id ); |
|
| 229 | + // Loop over possible entity properties. |
|
| 230 | + foreach ( $custom_fields as $key => $property ) { |
|
| 211 | 231 | |
| 212 | - } |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - } |
|
| 232 | + // Check presence of predicate and type. |
|
| 233 | + if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) { |
|
| 216 | 234 | |
| 217 | - /** |
|
| 218 | - * Separates metaboxes in simple and grouped. |
|
| 219 | - * |
|
| 220 | - * @param array $custom_fields Information on the entity type. |
|
| 221 | - * |
|
| 222 | - * @return array |
|
| 223 | - */ |
|
| 224 | - public function group_properties_by_input_field( $custom_fields ) { |
|
| 225 | - |
|
| 226 | - $simple_properties = array(); |
|
| 227 | - $grouped_properties = array(); |
|
| 228 | - |
|
| 229 | - // Loop over possible entity properties. |
|
| 230 | - foreach ( $custom_fields as $key => $property ) { |
|
| 231 | - |
|
| 232 | - // Check presence of predicate and type. |
|
| 233 | - if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) { |
|
| 234 | - |
|
| 235 | - // Check if input_field is defined. |
|
| 236 | - if ( isset( $property['input_field'] ) && '' !== $property['input_field'] ) { |
|
| 237 | - |
|
| 238 | - $grouped_key = $property['input_field']; |
|
| 239 | - |
|
| 240 | - // Update list of grouped properties. |
|
| 241 | - $grouped_properties[ $grouped_key ][ $key ] = $property; |
|
| 242 | - |
|
| 243 | - } else { |
|
| 244 | - |
|
| 245 | - // input_field not defined, add simple metabox. |
|
| 246 | - $simple_properties[ $key ] = $property; |
|
| 247 | - } |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - return array( $simple_properties, $grouped_properties ); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Add a Field to the current Metabox, based on the description of the Field. |
|
| 256 | - * This method is a rude factory for Field objects. |
|
| 257 | - * |
|
| 258 | - * @param array $args The field's information. |
|
| 259 | - * @param bool $grouped Flag to distinguish between simple and grouped fields. |
|
| 260 | - * @param int $type Post or Term, based on the correct decorator would be selected. |
|
| 261 | - * @param int $id Identifier for the type. |
|
| 262 | - */ |
|
| 263 | - public function add_field( $args, $grouped, $type, $id ) { |
|
| 264 | - |
|
| 265 | - if ( $grouped ) { |
|
| 266 | - |
|
| 267 | - // Special fields (sameas, coordinates, etc.). |
|
| 268 | - // |
|
| 269 | - // Build Field with a custom class (e.g. WL_Metabox_Field_date). |
|
| 270 | - $field_class = 'Wl_Metabox_Field_' . key( $args ); |
|
| 271 | - |
|
| 272 | - } else { |
|
| 273 | - |
|
| 274 | - // Simple fields (string, uri, boolean, etc.). |
|
| 275 | - // |
|
| 276 | - // Which field? We want to use the class that is specific for the field. |
|
| 277 | - $meta = key( $args ); |
|
| 278 | - $this_meta = $args[ $meta ]; |
|
| 279 | - |
|
| 280 | - // If the field declares what metabox it wants, use that one. |
|
| 281 | - if ( isset( $this_meta['metabox']['class'] ) ) { |
|
| 282 | - |
|
| 283 | - $field_class = $this_meta['metabox']['class']; |
|
| 284 | - |
|
| 285 | - } elseif ( ! isset( $this_meta['type'] ) || Wordlift_Schema_Service::DATA_TYPE_STRING === $this_meta['type'] ) { |
|
| 286 | - |
|
| 287 | - // TODO: all fields should explicitly declare the required WL_Metabox. |
|
| 288 | - // When they will remove this. |
|
| 289 | - // |
|
| 290 | - // Use default Wl_Metabox_Field (manages strings). |
|
| 291 | - $field_class = 'Wl_Metabox_Field'; |
|
| 292 | - |
|
| 293 | - } else { |
|
| 294 | - |
|
| 295 | - // TODO: all fields should explicitly declare the required WL_Metabox. |
|
| 296 | - // When they will remove this. |
|
| 297 | - // |
|
| 298 | - // Build Field with a custom class (e.g. Wl_Metabox_Field_date). |
|
| 299 | - $field_class = 'Wl_Metabox_Field_' . $this_meta['type']; |
|
| 300 | - |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - /** |
|
| 304 | - * @since 3.31.6 |
|
| 305 | - * Add namespace to initialize class. |
|
| 306 | - */ |
|
| 307 | - /** |
|
| 308 | - * @since 3.31.6 |
|
| 309 | - * Add namespace to initialize class. |
|
| 310 | - */ |
|
| 311 | - if ( substr( $field_class, 0, 1 ) !== '\\' ) { |
|
| 312 | - $field_class = 'Wordlift\Metabox\Field\\' . $field_class; |
|
| 313 | - // End if(). |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - if ( class_exists( $field_class ) ) { |
|
| 317 | - // Get decorator and use it as wrapper for save_data and get_data methods. |
|
| 318 | - $instance = new $field_class( $args, $id, $type ); |
|
| 319 | - // Call apropriate constructor (e.g. Wl_Metabox_Field... ). |
|
| 320 | - $this->fields[] = $instance; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * Save the form data for the specified entity {@link WP_Post}'s id. |
|
| 327 | - * |
|
| 328 | - * @param int $id The entity's {@link WP_Post}'s id. |
|
| 329 | - * |
|
| 330 | - * We're being called from WP `save_post` hook, we don't need to check the nonce. |
|
| 331 | - * |
|
| 332 | - * @param $type int Post or term |
|
| 333 | - * |
|
| 334 | - * @since 3.5.4 |
|
| 335 | - */ |
|
| 336 | - public function save_form_data( $id, $type ) { |
|
| 337 | - |
|
| 338 | - $this->log->trace( "Saving form data for entity post $id..." ); |
|
| 339 | - |
|
| 340 | - // Skip saving if the save is called for a different post. |
|
| 341 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 342 | - if ( isset( $_POST['post_ID'] ) && (int) $_POST['post_ID'] !== $id && Object_Type_Enum::POST === $type ) { |
|
| 343 | - $this->log->debug( '`wl_metaboxes`, skipping because the post id from request doesnt match the id from filter.' ); |
|
| 344 | - |
|
| 345 | - return; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - // Build Field objects. |
|
| 349 | - $this->instantiate_fields( $id, $type ); |
|
| 350 | - |
|
| 351 | - // Check if WL metabox form was posted. |
|
| 352 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 353 | - if ( ! isset( $_POST['wl_metaboxes'] ) ) { |
|
| 354 | - $this->log->debug( '`wl_metaboxes`, skipping...' ); |
|
| 355 | - |
|
| 356 | - return; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 360 | - $posted_data = filter_var_array( $_POST, array( 'wl_metaboxes' => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); |
|
| 361 | - $posted_data = $posted_data['wl_metaboxes']; |
|
| 362 | - foreach ( $this->fields as $field ) { |
|
| 363 | - |
|
| 364 | - // Verify nonce. |
|
| 365 | - $valid_nonce = $field->verify_nonce(); |
|
| 366 | - |
|
| 367 | - if ( $valid_nonce ) { |
|
| 368 | - $field_name = $field->meta_name; |
|
| 369 | - // Each Filed only deals with its values. |
|
| 370 | - if ( isset( $posted_data[ $field_name ] ) ) { |
|
| 371 | - |
|
| 372 | - $values = $posted_data[ $field_name ]; |
|
| 373 | - if ( ! is_array( $values ) ) { |
|
| 374 | - $values = array( $values ); |
|
| 375 | - } |
|
| 376 | - // Save data permanently |
|
| 377 | - $field->save_data( $values ); |
|
| 378 | - } |
|
| 379 | - } |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - /** |
|
| 383 | - * Filter: 'wl_save_form_pre_push_entity' - Allow to hook right |
|
| 384 | - * before the triples are pushed to the linked dataset. |
|
| 385 | - * |
|
| 386 | - * @param int $id The entity id. |
|
| 387 | - * @param int $id The post data. |
|
| 388 | - * |
|
| 389 | - * @since 3.18.2 |
|
| 390 | - */ |
|
| 391 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 392 | - do_action( 'wl_save_form_pre_push_entity', $id, $_POST ); |
|
| 393 | - |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * Enqueue scripts and styles. |
|
| 398 | - * |
|
| 399 | - * @since 3.0.0 |
|
| 400 | - */ |
|
| 401 | - public function enqueue_scripts_and_styles() { |
|
| 402 | - |
|
| 403 | - // Use the minified version if PW_DEBUG isn't set. |
|
| 404 | - $min = ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ? '.min' : ''; |
|
| 405 | - |
|
| 406 | - // Load the jquery-ui-timepicker-addon library. |
|
| 407 | - wp_enqueue_style( 'wl-flatpickr', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . "/admin/js/flatpickr/flatpickr$min.css", array(), '3.0.6' ); |
|
| 408 | - wp_enqueue_script( 'wl-flatpickr', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . "/admin/js/flatpickr/flatpickr$min.js", array( 'jquery' ), '3.0.6', true ); |
|
| 409 | - |
|
| 410 | - wl_enqueue_leaflet(); |
|
| 411 | - |
|
| 412 | - // Add AJAX autocomplete to facilitate metabox editing. |
|
| 413 | - wp_enqueue_script( 'wl-entity-metabox-utility', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/admin/js/wl_entity_metabox_utilities.js', array(), WORDLIFT_VERSION, false ); |
|
| 414 | - wp_localize_script( |
|
| 415 | - 'wl-entity-metabox-utility', |
|
| 416 | - 'wlEntityMetaboxParams', |
|
| 417 | - array( |
|
| 418 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 419 | - 'action' => 'entity_by_title', |
|
| 420 | - ) |
|
| 421 | - ); |
|
| 422 | - |
|
| 423 | - } |
|
| 235 | + // Check if input_field is defined. |
|
| 236 | + if ( isset( $property['input_field'] ) && '' !== $property['input_field'] ) { |
|
| 237 | + |
|
| 238 | + $grouped_key = $property['input_field']; |
|
| 239 | + |
|
| 240 | + // Update list of grouped properties. |
|
| 241 | + $grouped_properties[ $grouped_key ][ $key ] = $property; |
|
| 242 | + |
|
| 243 | + } else { |
|
| 244 | + |
|
| 245 | + // input_field not defined, add simple metabox. |
|
| 246 | + $simple_properties[ $key ] = $property; |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + return array( $simple_properties, $grouped_properties ); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Add a Field to the current Metabox, based on the description of the Field. |
|
| 256 | + * This method is a rude factory for Field objects. |
|
| 257 | + * |
|
| 258 | + * @param array $args The field's information. |
|
| 259 | + * @param bool $grouped Flag to distinguish between simple and grouped fields. |
|
| 260 | + * @param int $type Post or Term, based on the correct decorator would be selected. |
|
| 261 | + * @param int $id Identifier for the type. |
|
| 262 | + */ |
|
| 263 | + public function add_field( $args, $grouped, $type, $id ) { |
|
| 264 | + |
|
| 265 | + if ( $grouped ) { |
|
| 266 | + |
|
| 267 | + // Special fields (sameas, coordinates, etc.). |
|
| 268 | + // |
|
| 269 | + // Build Field with a custom class (e.g. WL_Metabox_Field_date). |
|
| 270 | + $field_class = 'Wl_Metabox_Field_' . key( $args ); |
|
| 271 | + |
|
| 272 | + } else { |
|
| 273 | + |
|
| 274 | + // Simple fields (string, uri, boolean, etc.). |
|
| 275 | + // |
|
| 276 | + // Which field? We want to use the class that is specific for the field. |
|
| 277 | + $meta = key( $args ); |
|
| 278 | + $this_meta = $args[ $meta ]; |
|
| 279 | + |
|
| 280 | + // If the field declares what metabox it wants, use that one. |
|
| 281 | + if ( isset( $this_meta['metabox']['class'] ) ) { |
|
| 282 | + |
|
| 283 | + $field_class = $this_meta['metabox']['class']; |
|
| 284 | + |
|
| 285 | + } elseif ( ! isset( $this_meta['type'] ) || Wordlift_Schema_Service::DATA_TYPE_STRING === $this_meta['type'] ) { |
|
| 286 | + |
|
| 287 | + // TODO: all fields should explicitly declare the required WL_Metabox. |
|
| 288 | + // When they will remove this. |
|
| 289 | + // |
|
| 290 | + // Use default Wl_Metabox_Field (manages strings). |
|
| 291 | + $field_class = 'Wl_Metabox_Field'; |
|
| 292 | + |
|
| 293 | + } else { |
|
| 294 | + |
|
| 295 | + // TODO: all fields should explicitly declare the required WL_Metabox. |
|
| 296 | + // When they will remove this. |
|
| 297 | + // |
|
| 298 | + // Build Field with a custom class (e.g. Wl_Metabox_Field_date). |
|
| 299 | + $field_class = 'Wl_Metabox_Field_' . $this_meta['type']; |
|
| 300 | + |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + /** |
|
| 304 | + * @since 3.31.6 |
|
| 305 | + * Add namespace to initialize class. |
|
| 306 | + */ |
|
| 307 | + /** |
|
| 308 | + * @since 3.31.6 |
|
| 309 | + * Add namespace to initialize class. |
|
| 310 | + */ |
|
| 311 | + if ( substr( $field_class, 0, 1 ) !== '\\' ) { |
|
| 312 | + $field_class = 'Wordlift\Metabox\Field\\' . $field_class; |
|
| 313 | + // End if(). |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + if ( class_exists( $field_class ) ) { |
|
| 317 | + // Get decorator and use it as wrapper for save_data and get_data methods. |
|
| 318 | + $instance = new $field_class( $args, $id, $type ); |
|
| 319 | + // Call apropriate constructor (e.g. Wl_Metabox_Field... ). |
|
| 320 | + $this->fields[] = $instance; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + /** |
|
| 326 | + * Save the form data for the specified entity {@link WP_Post}'s id. |
|
| 327 | + * |
|
| 328 | + * @param int $id The entity's {@link WP_Post}'s id. |
|
| 329 | + * |
|
| 330 | + * We're being called from WP `save_post` hook, we don't need to check the nonce. |
|
| 331 | + * |
|
| 332 | + * @param $type int Post or term |
|
| 333 | + * |
|
| 334 | + * @since 3.5.4 |
|
| 335 | + */ |
|
| 336 | + public function save_form_data( $id, $type ) { |
|
| 337 | + |
|
| 338 | + $this->log->trace( "Saving form data for entity post $id..." ); |
|
| 339 | + |
|
| 340 | + // Skip saving if the save is called for a different post. |
|
| 341 | + // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 342 | + if ( isset( $_POST['post_ID'] ) && (int) $_POST['post_ID'] !== $id && Object_Type_Enum::POST === $type ) { |
|
| 343 | + $this->log->debug( '`wl_metaboxes`, skipping because the post id from request doesnt match the id from filter.' ); |
|
| 344 | + |
|
| 345 | + return; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + // Build Field objects. |
|
| 349 | + $this->instantiate_fields( $id, $type ); |
|
| 350 | + |
|
| 351 | + // Check if WL metabox form was posted. |
|
| 352 | + // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 353 | + if ( ! isset( $_POST['wl_metaboxes'] ) ) { |
|
| 354 | + $this->log->debug( '`wl_metaboxes`, skipping...' ); |
|
| 355 | + |
|
| 356 | + return; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 360 | + $posted_data = filter_var_array( $_POST, array( 'wl_metaboxes' => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); |
|
| 361 | + $posted_data = $posted_data['wl_metaboxes']; |
|
| 362 | + foreach ( $this->fields as $field ) { |
|
| 363 | + |
|
| 364 | + // Verify nonce. |
|
| 365 | + $valid_nonce = $field->verify_nonce(); |
|
| 366 | + |
|
| 367 | + if ( $valid_nonce ) { |
|
| 368 | + $field_name = $field->meta_name; |
|
| 369 | + // Each Filed only deals with its values. |
|
| 370 | + if ( isset( $posted_data[ $field_name ] ) ) { |
|
| 371 | + |
|
| 372 | + $values = $posted_data[ $field_name ]; |
|
| 373 | + if ( ! is_array( $values ) ) { |
|
| 374 | + $values = array( $values ); |
|
| 375 | + } |
|
| 376 | + // Save data permanently |
|
| 377 | + $field->save_data( $values ); |
|
| 378 | + } |
|
| 379 | + } |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + /** |
|
| 383 | + * Filter: 'wl_save_form_pre_push_entity' - Allow to hook right |
|
| 384 | + * before the triples are pushed to the linked dataset. |
|
| 385 | + * |
|
| 386 | + * @param int $id The entity id. |
|
| 387 | + * @param int $id The post data. |
|
| 388 | + * |
|
| 389 | + * @since 3.18.2 |
|
| 390 | + */ |
|
| 391 | + // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 392 | + do_action( 'wl_save_form_pre_push_entity', $id, $_POST ); |
|
| 393 | + |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * Enqueue scripts and styles. |
|
| 398 | + * |
|
| 399 | + * @since 3.0.0 |
|
| 400 | + */ |
|
| 401 | + public function enqueue_scripts_and_styles() { |
|
| 402 | + |
|
| 403 | + // Use the minified version if PW_DEBUG isn't set. |
|
| 404 | + $min = ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ? '.min' : ''; |
|
| 405 | + |
|
| 406 | + // Load the jquery-ui-timepicker-addon library. |
|
| 407 | + wp_enqueue_style( 'wl-flatpickr', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . "/admin/js/flatpickr/flatpickr$min.css", array(), '3.0.6' ); |
|
| 408 | + wp_enqueue_script( 'wl-flatpickr', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . "/admin/js/flatpickr/flatpickr$min.js", array( 'jquery' ), '3.0.6', true ); |
|
| 409 | + |
|
| 410 | + wl_enqueue_leaflet(); |
|
| 411 | + |
|
| 412 | + // Add AJAX autocomplete to facilitate metabox editing. |
|
| 413 | + wp_enqueue_script( 'wl-entity-metabox-utility', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/admin/js/wl_entity_metabox_utilities.js', array(), WORDLIFT_VERSION, false ); |
|
| 414 | + wp_localize_script( |
|
| 415 | + 'wl-entity-metabox-utility', |
|
| 416 | + 'wlEntityMetaboxParams', |
|
| 417 | + array( |
|
| 418 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 419 | + 'action' => 'entity_by_title', |
|
| 420 | + ) |
|
| 421 | + ); |
|
| 422 | + |
|
| 423 | + } |
|
| 424 | 424 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function __construct() { |
| 43 | 43 | |
| 44 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 44 | + $this->log = Wordlift_Log_Service::get_logger(get_class()); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -51,22 +51,22 @@ discard block |
||
| 51 | 51 | public function add_main_metabox() { |
| 52 | 52 | |
| 53 | 53 | // Build the fields we need to print. |
| 54 | - $this->instantiate_fields( get_the_ID(), Object_Type_Enum::POST ); |
|
| 54 | + $this->instantiate_fields(get_the_ID(), Object_Type_Enum::POST); |
|
| 55 | 55 | |
| 56 | 56 | // Bailout if there are no actual fields, we do not need a metabox in that case. |
| 57 | - if ( empty( $this->fields ) ) { |
|
| 57 | + if (empty($this->fields)) { |
|
| 58 | 58 | return; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | // Add main metabox (will print also the inner fields). |
| 62 | - $id = uniqid( 'wl-metabox-' ); |
|
| 63 | - $title = __( 'WordLift', 'wordlift' ); |
|
| 62 | + $id = uniqid('wl-metabox-'); |
|
| 63 | + $title = __('WordLift', 'wordlift'); |
|
| 64 | 64 | |
| 65 | 65 | // WordPress 4.2 do not accept an array of screens as parameter, have to do be explicit. |
| 66 | - foreach ( Wordlift_Entity_Service::valid_entity_post_types() as $screen ) { |
|
| 66 | + foreach (Wordlift_Entity_Service::valid_entity_post_types() as $screen) { |
|
| 67 | 67 | add_meta_box( |
| 68 | 68 | $id, |
| 69 | - esc_html( $title ), |
|
| 69 | + esc_html($title), |
|
| 70 | 70 | array( |
| 71 | 71 | $this, |
| 72 | 72 | 'html', |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | // dynamically according to the `get_current_screen()` function. |
| 84 | 84 | $current_screen = get_current_screen(); |
| 85 | 85 | $screen = $current_screen ? $current_screen->post_type : 'entity'; |
| 86 | - add_filter( "postbox_classes_{$screen}_$id", 'wl_admin_metaboxes_add_css_class' ); |
|
| 86 | + add_filter("postbox_classes_{$screen}_$id", 'wl_admin_metaboxes_add_css_class'); |
|
| 87 | 87 | |
| 88 | 88 | } |
| 89 | 89 | |
@@ -95,16 +95,16 @@ discard block |
||
| 95 | 95 | public function html() { |
| 96 | 96 | |
| 97 | 97 | // HTML Code Before MetaBox Content. |
| 98 | - do_action( 'wl_metabox_before_html' ); |
|
| 98 | + do_action('wl_metabox_before_html'); |
|
| 99 | 99 | ?> |
| 100 | 100 | <div class="wl-tabs"> |
| 101 | 101 | |
| 102 | 102 | <input id="wl-tab-properties" type="radio" name="wl-metabox-tabs" checked="checked"/><label |
| 103 | - for="wl-tab-properties"><?php esc_html_e( 'Properties', 'wordlift' ); ?></label> |
|
| 103 | + for="wl-tab-properties"><?php esc_html_e('Properties', 'wordlift'); ?></label> |
|
| 104 | 104 | <div class="wl-tabs__tab"> |
| 105 | 105 | <?php |
| 106 | 106 | // Loop over the fields. |
| 107 | - foreach ( $this->fields as $field ) { |
|
| 107 | + foreach ($this->fields as $field) { |
|
| 108 | 108 | |
| 109 | 109 | // load data from DB (values will be available in $field->data). |
| 110 | 110 | $field->get_data(); |
@@ -117,13 +117,13 @@ discard block |
||
| 117 | 117 | <?php |
| 118 | 118 | // Only display the Main Ingredient tab if the feature is enabled. |
| 119 | 119 | // @@todo this tab shouldn't show if there are no ingredients. |
| 120 | - if ( apply_filters( 'wl_feature__enable__food-kg', false ) ) { |
|
| 120 | + if (apply_filters('wl_feature__enable__food-kg', false)) { |
|
| 121 | 121 | ?> |
| 122 | 122 | <input id="wl-tab-main-ingredient" type="radio" name="wl-metabox-tabs" checked="true"/><label |
| 123 | - for="wl-tab-main-ingredient"><?php esc_html_e( 'Main Ingredient', 'wordlift' ); ?></label> |
|
| 123 | + for="wl-tab-main-ingredient"><?php esc_html_e('Main Ingredient', 'wordlift'); ?></label> |
|
| 124 | 124 | <div class="wl-tabs__tab"> |
| 125 | 125 | <?php |
| 126 | - do_action( 'wl_ingredient_metabox_html' ); |
|
| 126 | + do_action('wl_ingredient_metabox_html'); |
|
| 127 | 127 | ?> |
| 128 | 128 | </div> |
| 129 | 129 | <?php |
@@ -144,20 +144,20 @@ discard block |
||
| 144 | 144 | * |
| 145 | 145 | * @since 3.1.0 |
| 146 | 146 | */ |
| 147 | - public function instantiate_fields( $id, $type ) { |
|
| 147 | + public function instantiate_fields($id, $type) { |
|
| 148 | 148 | |
| 149 | - $this->log->trace( "Instantiating fields for entity post $id..." ); |
|
| 149 | + $this->log->trace("Instantiating fields for entity post $id..."); |
|
| 150 | 150 | |
| 151 | 151 | // This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering. |
| 152 | - if ( isset( $this->fields ) ) { |
|
| 152 | + if (isset($this->fields)) { |
|
| 153 | 153 | return; |
| 154 | 154 | } |
| 155 | - if ( Object_Type_Enum::POST === $type ) { |
|
| 156 | - $entity_type = wl_entity_taxonomy_get_custom_fields( $id ); |
|
| 157 | - } elseif ( Object_Type_Enum::TERM === $type ) { |
|
| 158 | - $term_entity_types = get_term_meta( $id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 155 | + if (Object_Type_Enum::POST === $type) { |
|
| 156 | + $entity_type = wl_entity_taxonomy_get_custom_fields($id); |
|
| 157 | + } elseif (Object_Type_Enum::TERM === $type) { |
|
| 158 | + $term_entity_types = get_term_meta($id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME); |
|
| 159 | 159 | $term_entity_types = array_map( |
| 160 | - function ( $term ) { |
|
| 160 | + function($term) { |
|
| 161 | 161 | return get_term_by( |
| 162 | 162 | 'slug', |
| 163 | 163 | $term, |
@@ -166,9 +166,9 @@ discard block |
||
| 166 | 166 | }, |
| 167 | 167 | $term_entity_types |
| 168 | 168 | ); |
| 169 | - $entity_type = wl_get_custom_fields_by_entity_type( $term_entity_types ); |
|
| 169 | + $entity_type = wl_get_custom_fields_by_entity_type($term_entity_types); |
|
| 170 | 170 | } |
| 171 | - if ( isset( $entity_type ) ) { |
|
| 171 | + if (isset($entity_type)) { |
|
| 172 | 172 | |
| 173 | 173 | /* |
| 174 | 174 | * Might not have any relevant meta box field, for example for articles, |
@@ -183,31 +183,31 @@ discard block |
||
| 183 | 183 | * - simple: accept values for one property |
| 184 | 184 | * - grouped: accept values for more properties, or for one property that needs a specific metabox. |
| 185 | 185 | */ |
| 186 | - $metaboxes = $this->group_properties_by_input_field( $entity_type ); |
|
| 186 | + $metaboxes = $this->group_properties_by_input_field($entity_type); |
|
| 187 | 187 | $simple_metaboxes = $metaboxes[0]; |
| 188 | 188 | $grouped_metaboxes = $metaboxes[1]; |
| 189 | 189 | |
| 190 | 190 | // Loop over simple entity properties. |
| 191 | - foreach ( $simple_metaboxes as $key => $property ) { |
|
| 191 | + foreach ($simple_metaboxes as $key => $property) { |
|
| 192 | 192 | |
| 193 | 193 | // Info passed to the metabox. |
| 194 | 194 | $info = array(); |
| 195 | - $info[ $key ] = $property; |
|
| 195 | + $info[$key] = $property; |
|
| 196 | 196 | |
| 197 | 197 | // Build the requested field as WL_Metabox_Field_ object. |
| 198 | - $this->add_field( $info, false, $type, $id ); |
|
| 198 | + $this->add_field($info, false, $type, $id); |
|
| 199 | 199 | |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | // Loop over grouped properties. |
| 203 | - foreach ( $grouped_metaboxes as $key => $property ) { |
|
| 203 | + foreach ($grouped_metaboxes as $key => $property) { |
|
| 204 | 204 | |
| 205 | 205 | // Info passed to the metabox. |
| 206 | 206 | $info = array(); |
| 207 | - $info[ $key ] = $property; |
|
| 207 | + $info[$key] = $property; |
|
| 208 | 208 | |
| 209 | 209 | // Build the requested field group as WL_Metabox_Field_ object. |
| 210 | - $this->add_field( $info, true, $type, $id ); |
|
| 210 | + $this->add_field($info, true, $type, $id); |
|
| 211 | 211 | |
| 212 | 212 | } |
| 213 | 213 | } |
@@ -221,34 +221,34 @@ discard block |
||
| 221 | 221 | * |
| 222 | 222 | * @return array |
| 223 | 223 | */ |
| 224 | - public function group_properties_by_input_field( $custom_fields ) { |
|
| 224 | + public function group_properties_by_input_field($custom_fields) { |
|
| 225 | 225 | |
| 226 | 226 | $simple_properties = array(); |
| 227 | 227 | $grouped_properties = array(); |
| 228 | 228 | |
| 229 | 229 | // Loop over possible entity properties. |
| 230 | - foreach ( $custom_fields as $key => $property ) { |
|
| 230 | + foreach ($custom_fields as $key => $property) { |
|
| 231 | 231 | |
| 232 | 232 | // Check presence of predicate and type. |
| 233 | - if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) { |
|
| 233 | + if (isset($property['predicate']) && isset($property['type'])) { |
|
| 234 | 234 | |
| 235 | 235 | // Check if input_field is defined. |
| 236 | - if ( isset( $property['input_field'] ) && '' !== $property['input_field'] ) { |
|
| 236 | + if (isset($property['input_field']) && '' !== $property['input_field']) { |
|
| 237 | 237 | |
| 238 | 238 | $grouped_key = $property['input_field']; |
| 239 | 239 | |
| 240 | 240 | // Update list of grouped properties. |
| 241 | - $grouped_properties[ $grouped_key ][ $key ] = $property; |
|
| 241 | + $grouped_properties[$grouped_key][$key] = $property; |
|
| 242 | 242 | |
| 243 | 243 | } else { |
| 244 | 244 | |
| 245 | 245 | // input_field not defined, add simple metabox. |
| 246 | - $simple_properties[ $key ] = $property; |
|
| 246 | + $simple_properties[$key] = $property; |
|
| 247 | 247 | } |
| 248 | 248 | } |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | - return array( $simple_properties, $grouped_properties ); |
|
| 251 | + return array($simple_properties, $grouped_properties); |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | /** |
@@ -260,29 +260,29 @@ discard block |
||
| 260 | 260 | * @param int $type Post or Term, based on the correct decorator would be selected. |
| 261 | 261 | * @param int $id Identifier for the type. |
| 262 | 262 | */ |
| 263 | - public function add_field( $args, $grouped, $type, $id ) { |
|
| 263 | + public function add_field($args, $grouped, $type, $id) { |
|
| 264 | 264 | |
| 265 | - if ( $grouped ) { |
|
| 265 | + if ($grouped) { |
|
| 266 | 266 | |
| 267 | 267 | // Special fields (sameas, coordinates, etc.). |
| 268 | 268 | // |
| 269 | 269 | // Build Field with a custom class (e.g. WL_Metabox_Field_date). |
| 270 | - $field_class = 'Wl_Metabox_Field_' . key( $args ); |
|
| 270 | + $field_class = 'Wl_Metabox_Field_'.key($args); |
|
| 271 | 271 | |
| 272 | 272 | } else { |
| 273 | 273 | |
| 274 | 274 | // Simple fields (string, uri, boolean, etc.). |
| 275 | 275 | // |
| 276 | 276 | // Which field? We want to use the class that is specific for the field. |
| 277 | - $meta = key( $args ); |
|
| 278 | - $this_meta = $args[ $meta ]; |
|
| 277 | + $meta = key($args); |
|
| 278 | + $this_meta = $args[$meta]; |
|
| 279 | 279 | |
| 280 | 280 | // If the field declares what metabox it wants, use that one. |
| 281 | - if ( isset( $this_meta['metabox']['class'] ) ) { |
|
| 281 | + if (isset($this_meta['metabox']['class'])) { |
|
| 282 | 282 | |
| 283 | 283 | $field_class = $this_meta['metabox']['class']; |
| 284 | 284 | |
| 285 | - } elseif ( ! isset( $this_meta['type'] ) || Wordlift_Schema_Service::DATA_TYPE_STRING === $this_meta['type'] ) { |
|
| 285 | + } elseif ( ! isset($this_meta['type']) || Wordlift_Schema_Service::DATA_TYPE_STRING === $this_meta['type']) { |
|
| 286 | 286 | |
| 287 | 287 | // TODO: all fields should explicitly declare the required WL_Metabox. |
| 288 | 288 | // When they will remove this. |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | // When they will remove this. |
| 297 | 297 | // |
| 298 | 298 | // Build Field with a custom class (e.g. Wl_Metabox_Field_date). |
| 299 | - $field_class = 'Wl_Metabox_Field_' . $this_meta['type']; |
|
| 299 | + $field_class = 'Wl_Metabox_Field_'.$this_meta['type']; |
|
| 300 | 300 | |
| 301 | 301 | } |
| 302 | 302 | } |
@@ -308,14 +308,14 @@ discard block |
||
| 308 | 308 | * @since 3.31.6 |
| 309 | 309 | * Add namespace to initialize class. |
| 310 | 310 | */ |
| 311 | - if ( substr( $field_class, 0, 1 ) !== '\\' ) { |
|
| 312 | - $field_class = 'Wordlift\Metabox\Field\\' . $field_class; |
|
| 311 | + if (substr($field_class, 0, 1) !== '\\') { |
|
| 312 | + $field_class = 'Wordlift\Metabox\Field\\'.$field_class; |
|
| 313 | 313 | // End if(). |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | - if ( class_exists( $field_class ) ) { |
|
| 316 | + if (class_exists($field_class)) { |
|
| 317 | 317 | // Get decorator and use it as wrapper for save_data and get_data methods. |
| 318 | - $instance = new $field_class( $args, $id, $type ); |
|
| 318 | + $instance = new $field_class($args, $id, $type); |
|
| 319 | 319 | // Call apropriate constructor (e.g. Wl_Metabox_Field... ). |
| 320 | 320 | $this->fields[] = $instance; |
| 321 | 321 | } |
@@ -333,48 +333,48 @@ discard block |
||
| 333 | 333 | * |
| 334 | 334 | * @since 3.5.4 |
| 335 | 335 | */ |
| 336 | - public function save_form_data( $id, $type ) { |
|
| 336 | + public function save_form_data($id, $type) { |
|
| 337 | 337 | |
| 338 | - $this->log->trace( "Saving form data for entity post $id..." ); |
|
| 338 | + $this->log->trace("Saving form data for entity post $id..."); |
|
| 339 | 339 | |
| 340 | 340 | // Skip saving if the save is called for a different post. |
| 341 | 341 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 342 | - if ( isset( $_POST['post_ID'] ) && (int) $_POST['post_ID'] !== $id && Object_Type_Enum::POST === $type ) { |
|
| 343 | - $this->log->debug( '`wl_metaboxes`, skipping because the post id from request doesnt match the id from filter.' ); |
|
| 342 | + if (isset($_POST['post_ID']) && (int) $_POST['post_ID'] !== $id && Object_Type_Enum::POST === $type) { |
|
| 343 | + $this->log->debug('`wl_metaboxes`, skipping because the post id from request doesnt match the id from filter.'); |
|
| 344 | 344 | |
| 345 | 345 | return; |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | // Build Field objects. |
| 349 | - $this->instantiate_fields( $id, $type ); |
|
| 349 | + $this->instantiate_fields($id, $type); |
|
| 350 | 350 | |
| 351 | 351 | // Check if WL metabox form was posted. |
| 352 | 352 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 353 | - if ( ! isset( $_POST['wl_metaboxes'] ) ) { |
|
| 354 | - $this->log->debug( '`wl_metaboxes`, skipping...' ); |
|
| 353 | + if ( ! isset($_POST['wl_metaboxes'])) { |
|
| 354 | + $this->log->debug('`wl_metaboxes`, skipping...'); |
|
| 355 | 355 | |
| 356 | 356 | return; |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 360 | - $posted_data = filter_var_array( $_POST, array( 'wl_metaboxes' => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); |
|
| 360 | + $posted_data = filter_var_array($_POST, array('wl_metaboxes' => array('flags' => FILTER_REQUIRE_ARRAY))); |
|
| 361 | 361 | $posted_data = $posted_data['wl_metaboxes']; |
| 362 | - foreach ( $this->fields as $field ) { |
|
| 362 | + foreach ($this->fields as $field) { |
|
| 363 | 363 | |
| 364 | 364 | // Verify nonce. |
| 365 | 365 | $valid_nonce = $field->verify_nonce(); |
| 366 | 366 | |
| 367 | - if ( $valid_nonce ) { |
|
| 367 | + if ($valid_nonce) { |
|
| 368 | 368 | $field_name = $field->meta_name; |
| 369 | 369 | // Each Filed only deals with its values. |
| 370 | - if ( isset( $posted_data[ $field_name ] ) ) { |
|
| 370 | + if (isset($posted_data[$field_name])) { |
|
| 371 | 371 | |
| 372 | - $values = $posted_data[ $field_name ]; |
|
| 373 | - if ( ! is_array( $values ) ) { |
|
| 374 | - $values = array( $values ); |
|
| 372 | + $values = $posted_data[$field_name]; |
|
| 373 | + if ( ! is_array($values)) { |
|
| 374 | + $values = array($values); |
|
| 375 | 375 | } |
| 376 | 376 | // Save data permanently |
| 377 | - $field->save_data( $values ); |
|
| 377 | + $field->save_data($values); |
|
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | 380 | } |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | * @since 3.18.2 |
| 390 | 390 | */ |
| 391 | 391 | // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 392 | - do_action( 'wl_save_form_pre_push_entity', $id, $_POST ); |
|
| 392 | + do_action('wl_save_form_pre_push_entity', $id, $_POST); |
|
| 393 | 393 | |
| 394 | 394 | } |
| 395 | 395 | |
@@ -401,21 +401,21 @@ discard block |
||
| 401 | 401 | public function enqueue_scripts_and_styles() { |
| 402 | 402 | |
| 403 | 403 | // Use the minified version if PW_DEBUG isn't set. |
| 404 | - $min = ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ? '.min' : ''; |
|
| 404 | + $min = ! defined('WP_DEBUG') || ! WP_DEBUG ? '.min' : ''; |
|
| 405 | 405 | |
| 406 | 406 | // Load the jquery-ui-timepicker-addon library. |
| 407 | - wp_enqueue_style( 'wl-flatpickr', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . "/admin/js/flatpickr/flatpickr$min.css", array(), '3.0.6' ); |
|
| 408 | - wp_enqueue_script( 'wl-flatpickr', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . "/admin/js/flatpickr/flatpickr$min.js", array( 'jquery' ), '3.0.6', true ); |
|
| 407 | + wp_enqueue_style('wl-flatpickr', dirname(dirname(plugin_dir_url(__FILE__)))."/admin/js/flatpickr/flatpickr$min.css", array(), '3.0.6'); |
|
| 408 | + wp_enqueue_script('wl-flatpickr', dirname(dirname(plugin_dir_url(__FILE__)))."/admin/js/flatpickr/flatpickr$min.js", array('jquery'), '3.0.6', true); |
|
| 409 | 409 | |
| 410 | 410 | wl_enqueue_leaflet(); |
| 411 | 411 | |
| 412 | 412 | // Add AJAX autocomplete to facilitate metabox editing. |
| 413 | - wp_enqueue_script( 'wl-entity-metabox-utility', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/admin/js/wl_entity_metabox_utilities.js', array(), WORDLIFT_VERSION, false ); |
|
| 413 | + wp_enqueue_script('wl-entity-metabox-utility', dirname(dirname(plugin_dir_url(__FILE__))).'/admin/js/wl_entity_metabox_utilities.js', array(), WORDLIFT_VERSION, false); |
|
| 414 | 414 | wp_localize_script( |
| 415 | 415 | 'wl-entity-metabox-utility', |
| 416 | 416 | 'wlEntityMetaboxParams', |
| 417 | 417 | array( |
| 418 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 418 | + 'ajax_url' => admin_url('admin-ajax.php'), |
|
| 419 | 419 | 'action' => 'entity_by_title', |
| 420 | 420 | ) |
| 421 | 421 | ); |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | namespace Wordlift\Modules\Food_Kg\Admin; |
| 4 | 4 | |
| 5 | 5 | if ( ! class_exists( 'WP_List_Table' ) ) { |
| 6 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 6 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | use WP_List_Table; |
@@ -11,30 +11,30 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | class Main_Ingredient_List_Table extends WP_List_Table { |
| 13 | 13 | |
| 14 | - public function prepare_items() { |
|
| 15 | - global $wpdb; // This is used only if making any database queries |
|
| 16 | - |
|
| 17 | - /** |
|
| 18 | - * REQUIRED. Now we need to define our column headers. This includes a complete |
|
| 19 | - * array of columns to be displayed (slugs & titles), a list of columns |
|
| 20 | - * to keep hidden, and a list of columns that are sortable. Each of these |
|
| 21 | - * can be defined in another method (as we've done here) before being |
|
| 22 | - * used to build the value for our _column_headers property. |
|
| 23 | - */ |
|
| 24 | - $columns = $this->get_columns(); |
|
| 25 | - $hidden = array(); |
|
| 26 | - $sortable = $this->get_sortable_columns(); |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * REQUIRED. Finally, we build an array to be used by the class for column |
|
| 30 | - * headers. The $this->_column_headers property takes an array which contains |
|
| 31 | - * 3 other arrays. One for all columns, one for hidden columns, and one |
|
| 32 | - * for sortable columns. |
|
| 33 | - */ |
|
| 34 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 35 | - |
|
| 36 | - $this->items = $wpdb->get_results( |
|
| 37 | - "SELECT p1.ID AS recipe_ID, |
|
| 14 | + public function prepare_items() { |
|
| 15 | + global $wpdb; // This is used only if making any database queries |
|
| 16 | + |
|
| 17 | + /** |
|
| 18 | + * REQUIRED. Now we need to define our column headers. This includes a complete |
|
| 19 | + * array of columns to be displayed (slugs & titles), a list of columns |
|
| 20 | + * to keep hidden, and a list of columns that are sortable. Each of these |
|
| 21 | + * can be defined in another method (as we've done here) before being |
|
| 22 | + * used to build the value for our _column_headers property. |
|
| 23 | + */ |
|
| 24 | + $columns = $this->get_columns(); |
|
| 25 | + $hidden = array(); |
|
| 26 | + $sortable = $this->get_sortable_columns(); |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * REQUIRED. Finally, we build an array to be used by the class for column |
|
| 30 | + * headers. The $this->_column_headers property takes an array which contains |
|
| 31 | + * 3 other arrays. One for all columns, one for hidden columns, and one |
|
| 32 | + * for sortable columns. |
|
| 33 | + */ |
|
| 34 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 35 | + |
|
| 36 | + $this->items = $wpdb->get_results( |
|
| 37 | + "SELECT p1.ID AS recipe_ID, |
|
| 38 | 38 | p1.post_title AS recipe_name, |
| 39 | 39 | p2.ID AS post_ID, |
| 40 | 40 | p2.post_title, |
@@ -46,47 +46,47 @@ discard block |
||
| 46 | 46 | ON p2.post_content LIKE CONCAT( '%<!--WPRM Recipe ', p1.ID,'-->%' ) |
| 47 | 47 | AND p2.post_status = 'publish' |
| 48 | 48 | WHERE p1.post_type = 'wprm_recipe'" |
| 49 | - ); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - public function no_items() { |
|
| 53 | - esc_html_e( 'No main ingredients found.', 'wordlift' ); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - public function get_columns() { |
|
| 57 | - return array( |
|
| 58 | - 'recipe_name' => __( 'Recipe Name', 'wordlift' ), |
|
| 59 | - 'post_title' => __( 'Post Title', 'wordlift' ), |
|
| 60 | - 'url' => __( 'Post URL', 'wordlift' ), |
|
| 61 | - 'actions' => '', |
|
| 62 | - ); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - public function column_recipe_name( $item ) { |
|
| 66 | - return $item->recipe_name; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - public function column_post_title( $item ) { |
|
| 70 | - return sprintf( '<a href="%s">%s</a>', get_edit_post_link( $item->post_ID ), $item->post_title ); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - public function column_url( $item ) { |
|
| 74 | - return get_permalink( $item->post_ID ); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - public function column_actions( $item ) { |
|
| 78 | - |
|
| 79 | - $url = admin_url( |
|
| 80 | - sprintf( 'admin.php?page=wl_ingredients&modal_window=true&id=%d&TB_iframe=true', $item->ID ) |
|
| 81 | - ); |
|
| 82 | - |
|
| 83 | - return sprintf( |
|
| 84 | - '<a href="%s" class="button alignright thickbox open-plugin-details-modal" data-title="%s" type="button">%s</a>', |
|
| 85 | - $url, |
|
| 86 | - esc_attr( $item->post_title ), |
|
| 87 | - esc_html__( 'JSON-LD', 'wordlift' ) |
|
| 88 | - ); |
|
| 89 | - } |
|
| 49 | + ); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + public function no_items() { |
|
| 53 | + esc_html_e( 'No main ingredients found.', 'wordlift' ); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + public function get_columns() { |
|
| 57 | + return array( |
|
| 58 | + 'recipe_name' => __( 'Recipe Name', 'wordlift' ), |
|
| 59 | + 'post_title' => __( 'Post Title', 'wordlift' ), |
|
| 60 | + 'url' => __( 'Post URL', 'wordlift' ), |
|
| 61 | + 'actions' => '', |
|
| 62 | + ); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + public function column_recipe_name( $item ) { |
|
| 66 | + return $item->recipe_name; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + public function column_post_title( $item ) { |
|
| 70 | + return sprintf( '<a href="%s">%s</a>', get_edit_post_link( $item->post_ID ), $item->post_title ); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + public function column_url( $item ) { |
|
| 74 | + return get_permalink( $item->post_ID ); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + public function column_actions( $item ) { |
|
| 78 | + |
|
| 79 | + $url = admin_url( |
|
| 80 | + sprintf( 'admin.php?page=wl_ingredients&modal_window=true&id=%d&TB_iframe=true', $item->ID ) |
|
| 81 | + ); |
|
| 82 | + |
|
| 83 | + return sprintf( |
|
| 84 | + '<a href="%s" class="button alignright thickbox open-plugin-details-modal" data-title="%s" type="button">%s</a>', |
|
| 85 | + $url, |
|
| 86 | + esc_attr( $item->post_title ), |
|
| 87 | + esc_html__( 'JSON-LD', 'wordlift' ) |
|
| 88 | + ); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | 91 | } |
| 92 | 92 | |
@@ -2,8 +2,8 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | namespace Wordlift\Modules\Food_Kg\Admin; |
| 4 | 4 | |
| 5 | -if ( ! class_exists( 'WP_List_Table' ) ) { |
|
| 6 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
| 5 | +if ( ! class_exists('WP_List_Table')) { |
|
| 6 | + require_once ABSPATH.'wp-admin/includes/class-wp-list-table.php'; |
|
| 7 | 7 | } |
| 8 | 8 | |
| 9 | 9 | use WP_List_Table; |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * 3 other arrays. One for all columns, one for hidden columns, and one |
| 32 | 32 | * for sortable columns. |
| 33 | 33 | */ |
| 34 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
| 34 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
| 35 | 35 | |
| 36 | 36 | $this->items = $wpdb->get_results( |
| 37 | 37 | "SELECT p1.ID AS recipe_ID, |
@@ -50,41 +50,41 @@ discard block |
||
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | public function no_items() { |
| 53 | - esc_html_e( 'No main ingredients found.', 'wordlift' ); |
|
| 53 | + esc_html_e('No main ingredients found.', 'wordlift'); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | public function get_columns() { |
| 57 | 57 | return array( |
| 58 | - 'recipe_name' => __( 'Recipe Name', 'wordlift' ), |
|
| 59 | - 'post_title' => __( 'Post Title', 'wordlift' ), |
|
| 60 | - 'url' => __( 'Post URL', 'wordlift' ), |
|
| 58 | + 'recipe_name' => __('Recipe Name', 'wordlift'), |
|
| 59 | + 'post_title' => __('Post Title', 'wordlift'), |
|
| 60 | + 'url' => __('Post URL', 'wordlift'), |
|
| 61 | 61 | 'actions' => '', |
| 62 | 62 | ); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - public function column_recipe_name( $item ) { |
|
| 65 | + public function column_recipe_name($item) { |
|
| 66 | 66 | return $item->recipe_name; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - public function column_post_title( $item ) { |
|
| 70 | - return sprintf( '<a href="%s">%s</a>', get_edit_post_link( $item->post_ID ), $item->post_title ); |
|
| 69 | + public function column_post_title($item) { |
|
| 70 | + return sprintf('<a href="%s">%s</a>', get_edit_post_link($item->post_ID), $item->post_title); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - public function column_url( $item ) { |
|
| 74 | - return get_permalink( $item->post_ID ); |
|
| 73 | + public function column_url($item) { |
|
| 74 | + return get_permalink($item->post_ID); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - public function column_actions( $item ) { |
|
| 77 | + public function column_actions($item) { |
|
| 78 | 78 | |
| 79 | 79 | $url = admin_url( |
| 80 | - sprintf( 'admin.php?page=wl_ingredients&modal_window=true&id=%d&TB_iframe=true', $item->ID ) |
|
| 80 | + sprintf('admin.php?page=wl_ingredients&modal_window=true&id=%d&TB_iframe=true', $item->ID) |
|
| 81 | 81 | ); |
| 82 | 82 | |
| 83 | 83 | return sprintf( |
| 84 | 84 | '<a href="%s" class="button alignright thickbox open-plugin-details-modal" data-title="%s" type="button">%s</a>', |
| 85 | 85 | $url, |
| 86 | - esc_attr( $item->post_title ), |
|
| 87 | - esc_html__( 'JSON-LD', 'wordlift' ) |
|
| 86 | + esc_attr($item->post_title), |
|
| 87 | + esc_html__('JSON-LD', 'wordlift') |
|
| 88 | 88 | ); |
| 89 | 89 | } |
| 90 | 90 | |
@@ -4,17 +4,17 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | class Download_Ingredients_Data { |
| 6 | 6 | |
| 7 | - public function register_hooks() { |
|
| 8 | - add_action( 'wp_ajax_wl_download_ingredients_data', array( $this, 'wl_download_ingredients_data' ) ); |
|
| 9 | - } |
|
| 7 | + public function register_hooks() { |
|
| 8 | + add_action( 'wp_ajax_wl_download_ingredients_data', array( $this, 'wl_download_ingredients_data' ) ); |
|
| 9 | + } |
|
| 10 | 10 | |
| 11 | - public function wl_download_ingredients_data() { |
|
| 12 | - global $wpdb; |
|
| 11 | + public function wl_download_ingredients_data() { |
|
| 12 | + global $wpdb; |
|
| 13 | 13 | |
| 14 | - // @@todo add the admin capability check + nonce. |
|
| 14 | + // @@todo add the admin capability check + nonce. |
|
| 15 | 15 | |
| 16 | - $items = $wpdb->get_results( |
|
| 17 | - "SELECT p1.ID AS recipe_ID, |
|
| 16 | + $items = $wpdb->get_results( |
|
| 17 | + "SELECT p1.ID AS recipe_ID, |
|
| 18 | 18 | p1.post_title AS recipe_name, |
| 19 | 19 | p2.ID AS post_ID, |
| 20 | 20 | p2.post_title, |
@@ -27,49 +27,49 @@ discard block |
||
| 27 | 27 | AND p2.post_status = 'publish' |
| 28 | 28 | WHERE p1.post_type = 'wprm_recipe'" ); |
| 29 | 29 | |
| 30 | - if ( ! $items ) { |
|
| 31 | - wp_send_json_error( __( 'No main ingredients found.', 'wordlift' ) ); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - $tsv = array(); |
|
| 35 | - |
|
| 36 | - foreach ( $items as $item ) { |
|
| 37 | - // @@todo write straight to the output. |
|
| 38 | - // @@todo print the ingredient name and the ingredient @id. |
|
| 39 | - // @@todo use tab as separator. |
|
| 40 | - // @@todo also output the post ID and recipe ID. |
|
| 41 | - $tsv[] = array( |
|
| 42 | - $item->post_title, |
|
| 43 | - esc_url( get_the_permalink( $item->post_ID ) ), |
|
| 44 | - ); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - // Generate unique filename using current timestamp. |
|
| 48 | - $filename = 'wl-main-ingredients-data-' . gmdate( 'Y-m-d-H-i-s' ) . '.tsv'; |
|
| 49 | - |
|
| 50 | - header( 'Content-Disposition: attachment; filename=' . $filename ); |
|
| 51 | - header( 'Content-Type: text/tsv; charset=' . get_bloginfo( 'charset' ) ); |
|
| 52 | - |
|
| 53 | - // Do not cache the file. |
|
| 54 | - header( 'Pragma: no-cache' ); |
|
| 55 | - header( 'Expires: 0' ); |
|
| 56 | - |
|
| 57 | - $output = fopen( 'php://output', 'w' ); |
|
| 58 | - |
|
| 59 | - // Insert Header. |
|
| 60 | - fputcsv( |
|
| 61 | - $output, |
|
| 62 | - array( |
|
| 63 | - __( 'Name', 'wordlift' ), |
|
| 64 | - __( 'URL', 'wordlift' ), |
|
| 65 | - ) |
|
| 66 | - ); |
|
| 67 | - |
|
| 68 | - // Insert Data. |
|
| 69 | - foreach ( $tsv as $row ) { |
|
| 70 | - fputcsv( $output, $row ); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - wp_die(); |
|
| 74 | - } |
|
| 30 | + if ( ! $items ) { |
|
| 31 | + wp_send_json_error( __( 'No main ingredients found.', 'wordlift' ) ); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + $tsv = array(); |
|
| 35 | + |
|
| 36 | + foreach ( $items as $item ) { |
|
| 37 | + // @@todo write straight to the output. |
|
| 38 | + // @@todo print the ingredient name and the ingredient @id. |
|
| 39 | + // @@todo use tab as separator. |
|
| 40 | + // @@todo also output the post ID and recipe ID. |
|
| 41 | + $tsv[] = array( |
|
| 42 | + $item->post_title, |
|
| 43 | + esc_url( get_the_permalink( $item->post_ID ) ), |
|
| 44 | + ); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + // Generate unique filename using current timestamp. |
|
| 48 | + $filename = 'wl-main-ingredients-data-' . gmdate( 'Y-m-d-H-i-s' ) . '.tsv'; |
|
| 49 | + |
|
| 50 | + header( 'Content-Disposition: attachment; filename=' . $filename ); |
|
| 51 | + header( 'Content-Type: text/tsv; charset=' . get_bloginfo( 'charset' ) ); |
|
| 52 | + |
|
| 53 | + // Do not cache the file. |
|
| 54 | + header( 'Pragma: no-cache' ); |
|
| 55 | + header( 'Expires: 0' ); |
|
| 56 | + |
|
| 57 | + $output = fopen( 'php://output', 'w' ); |
|
| 58 | + |
|
| 59 | + // Insert Header. |
|
| 60 | + fputcsv( |
|
| 61 | + $output, |
|
| 62 | + array( |
|
| 63 | + __( 'Name', 'wordlift' ), |
|
| 64 | + __( 'URL', 'wordlift' ), |
|
| 65 | + ) |
|
| 66 | + ); |
|
| 67 | + |
|
| 68 | + // Insert Data. |
|
| 69 | + foreach ( $tsv as $row ) { |
|
| 70 | + fputcsv( $output, $row ); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + wp_die(); |
|
| 74 | + } |
|
| 75 | 75 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | class Download_Ingredients_Data { |
| 6 | 6 | |
| 7 | 7 | public function register_hooks() { |
| 8 | - add_action( 'wp_ajax_wl_download_ingredients_data', array( $this, 'wl_download_ingredients_data' ) ); |
|
| 8 | + add_action('wp_ajax_wl_download_ingredients_data', array($this, 'wl_download_ingredients_data')); |
|
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | public function wl_download_ingredients_data() { |
@@ -27,47 +27,47 @@ discard block |
||
| 27 | 27 | AND p2.post_status = 'publish' |
| 28 | 28 | WHERE p1.post_type = 'wprm_recipe'" ); |
| 29 | 29 | |
| 30 | - if ( ! $items ) { |
|
| 31 | - wp_send_json_error( __( 'No main ingredients found.', 'wordlift' ) ); |
|
| 30 | + if ( ! $items) { |
|
| 31 | + wp_send_json_error(__('No main ingredients found.', 'wordlift')); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | $tsv = array(); |
| 35 | 35 | |
| 36 | - foreach ( $items as $item ) { |
|
| 36 | + foreach ($items as $item) { |
|
| 37 | 37 | // @@todo write straight to the output. |
| 38 | 38 | // @@todo print the ingredient name and the ingredient @id. |
| 39 | 39 | // @@todo use tab as separator. |
| 40 | 40 | // @@todo also output the post ID and recipe ID. |
| 41 | 41 | $tsv[] = array( |
| 42 | 42 | $item->post_title, |
| 43 | - esc_url( get_the_permalink( $item->post_ID ) ), |
|
| 43 | + esc_url(get_the_permalink($item->post_ID)), |
|
| 44 | 44 | ); |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | // Generate unique filename using current timestamp. |
| 48 | - $filename = 'wl-main-ingredients-data-' . gmdate( 'Y-m-d-H-i-s' ) . '.tsv'; |
|
| 48 | + $filename = 'wl-main-ingredients-data-'.gmdate('Y-m-d-H-i-s').'.tsv'; |
|
| 49 | 49 | |
| 50 | - header( 'Content-Disposition: attachment; filename=' . $filename ); |
|
| 51 | - header( 'Content-Type: text/tsv; charset=' . get_bloginfo( 'charset' ) ); |
|
| 50 | + header('Content-Disposition: attachment; filename='.$filename); |
|
| 51 | + header('Content-Type: text/tsv; charset='.get_bloginfo('charset')); |
|
| 52 | 52 | |
| 53 | 53 | // Do not cache the file. |
| 54 | - header( 'Pragma: no-cache' ); |
|
| 55 | - header( 'Expires: 0' ); |
|
| 54 | + header('Pragma: no-cache'); |
|
| 55 | + header('Expires: 0'); |
|
| 56 | 56 | |
| 57 | - $output = fopen( 'php://output', 'w' ); |
|
| 57 | + $output = fopen('php://output', 'w'); |
|
| 58 | 58 | |
| 59 | 59 | // Insert Header. |
| 60 | 60 | fputcsv( |
| 61 | 61 | $output, |
| 62 | 62 | array( |
| 63 | - __( 'Name', 'wordlift' ), |
|
| 64 | - __( 'URL', 'wordlift' ), |
|
| 63 | + __('Name', 'wordlift'), |
|
| 64 | + __('URL', 'wordlift'), |
|
| 65 | 65 | ) |
| 66 | 66 | ); |
| 67 | 67 | |
| 68 | 68 | // Insert Data. |
| 69 | - foreach ( $tsv as $row ) { |
|
| 70 | - fputcsv( $output, $row ); |
|
| 69 | + foreach ($tsv as $row) { |
|
| 70 | + fputcsv($output, $row); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | wp_die(); |