@@ -24,23 +24,23 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | function wl_transition_post_status( $new_status, $old_status, $post ) { |
| 26 | 26 | |
| 27 | - // wl_write_log( "wl_transition_post_status [ new status :: $new_status ][ old status :: $old_status ][ post ID :: $post->ID ]" ); |
|
| 28 | - |
|
| 29 | - // transition from *published* to any other status: delete the post. |
|
| 30 | - if ( 'publish' === $old_status && 'publish' !== $new_status ) { |
|
| 31 | - // Delete the post from the triple store. |
|
| 32 | - rl_delete_post( $post ); |
|
| 33 | - |
|
| 34 | - // Remove all relation instances for the current post from `wl_relation_instances`. |
|
| 35 | - wl_core_delete_relation_instances( $post->ID ); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - // when a post is published, then all the referenced entities must be published. |
|
| 39 | - if ( 'publish' !== $old_status && 'publish' === $new_status ) { |
|
| 40 | - foreach ( wl_core_get_related_entity_ids( $post->ID ) as $entity_id ) { |
|
| 41 | - wl_update_post_status( $entity_id, 'publish' ); |
|
| 42 | - } |
|
| 43 | - } |
|
| 27 | + // wl_write_log( "wl_transition_post_status [ new status :: $new_status ][ old status :: $old_status ][ post ID :: $post->ID ]" ); |
|
| 28 | + |
|
| 29 | + // transition from *published* to any other status: delete the post. |
|
| 30 | + if ( 'publish' === $old_status && 'publish' !== $new_status ) { |
|
| 31 | + // Delete the post from the triple store. |
|
| 32 | + rl_delete_post( $post ); |
|
| 33 | + |
|
| 34 | + // Remove all relation instances for the current post from `wl_relation_instances`. |
|
| 35 | + wl_core_delete_relation_instances( $post->ID ); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + // when a post is published, then all the referenced entities must be published. |
|
| 39 | + if ( 'publish' !== $old_status && 'publish' === $new_status ) { |
|
| 40 | + foreach ( wl_core_get_related_entity_ids( $post->ID ) as $entity_id ) { |
|
| 41 | + wl_update_post_status( $entity_id, 'publish' ); |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | // hook save events. |
@@ -54,10 +54,10 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | function rl_delete_post( $post ) { |
| 56 | 56 | |
| 57 | - $post_id = ( is_numeric( $post ) ? $post : $post->ID ); |
|
| 57 | + $post_id = ( is_numeric( $post ) ? $post : $post->ID ); |
|
| 58 | 58 | |
| 59 | - // Remove the post. |
|
| 60 | - Wordlift_Linked_Data_Service::get_instance()->remove( $post_id ); |
|
| 59 | + // Remove the post. |
|
| 60 | + Wordlift_Linked_Data_Service::get_instance()->remove( $post_id ); |
|
| 61 | 61 | |
| 62 | 62 | } |
| 63 | 63 | |
@@ -69,35 +69,35 @@ discard block |
||
| 69 | 69 | */ |
| 70 | 70 | function wl_update_post_status( $post_id, $status ) { |
| 71 | 71 | |
| 72 | - wl_write_log( "wl_update_post_status [ post ID :: $post_id ][ status :: $status ]" ); |
|
| 72 | + wl_write_log( "wl_update_post_status [ post ID :: $post_id ][ status :: $status ]" ); |
|
| 73 | 73 | |
| 74 | - global $wpdb; |
|
| 74 | + global $wpdb; |
|
| 75 | 75 | |
| 76 | - if ( ! $post = get_post( $post_id ) ) { |
|
| 77 | - return; |
|
| 78 | - } |
|
| 76 | + if ( ! $post = get_post( $post_id ) ) { |
|
| 77 | + return; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - if ( $status === $post->post_status ) { |
|
| 81 | - return; |
|
| 82 | - } |
|
| 80 | + if ( $status === $post->post_status ) { |
|
| 81 | + return; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - wl_write_log( "wl_update_post_status, old and new post status do not match [ post ID :: $post_id ][ new status :: $status ][ old status :: $post->post_status ]." ); |
|
| 84 | + wl_write_log( "wl_update_post_status, old and new post status do not match [ post ID :: $post_id ][ new status :: $status ][ old status :: $post->post_status ]." ); |
|
| 85 | 85 | |
| 86 | - $wpdb->update( $wpdb->posts, array( 'post_status' => $status ), array( 'ID' => $post->ID ) ); |
|
| 86 | + $wpdb->update( $wpdb->posts, array( 'post_status' => $status ), array( 'ID' => $post->ID ) ); |
|
| 87 | 87 | |
| 88 | - clean_post_cache( $post->ID ); |
|
| 88 | + clean_post_cache( $post->ID ); |
|
| 89 | 89 | |
| 90 | - $old_status = $post->post_status; |
|
| 91 | - $post->post_status = $status; |
|
| 90 | + $old_status = $post->post_status; |
|
| 91 | + $post->post_status = $status; |
|
| 92 | 92 | |
| 93 | - wp_transition_post_status( $status, $old_status, $post ); |
|
| 93 | + wp_transition_post_status( $status, $old_status, $post ); |
|
| 94 | 94 | |
| 95 | - /** This action is documented in wp-includes/post.php */ |
|
| 96 | - do_action( 'edit_post', $post->ID, $post ); |
|
| 97 | - /** This action is documented in wp-includes/post.php */ |
|
| 98 | - do_action( "save_post_{$post->post_type}", $post->ID, $post, true ); |
|
| 99 | - /** This action is documented in wp-includes/post.php */ |
|
| 100 | - do_action( 'wl_linked_data_save_post', $post->ID ); |
|
| 101 | - /** This action is documented in wp-includes/post.php */ |
|
| 102 | - do_action( 'wp_insert_post', $post->ID, $post, true ); |
|
| 95 | + /** This action is documented in wp-includes/post.php */ |
|
| 96 | + do_action( 'edit_post', $post->ID, $post ); |
|
| 97 | + /** This action is documented in wp-includes/post.php */ |
|
| 98 | + do_action( "save_post_{$post->post_type}", $post->ID, $post, true ); |
|
| 99 | + /** This action is documented in wp-includes/post.php */ |
|
| 100 | + do_action( 'wl_linked_data_save_post', $post->ID ); |
|
| 101 | + /** This action is documented in wp-includes/post.php */ |
|
| 102 | + do_action( 'wp_insert_post', $post->ID, $post, true ); |
|
| 103 | 103 | } |
@@ -22,29 +22,29 @@ discard block |
||
| 22 | 22 | * @param string $old_status The old post status |
| 23 | 23 | * @param array $post An array with the post data |
| 24 | 24 | */ |
| 25 | -function wl_transition_post_status( $new_status, $old_status, $post ) { |
|
| 25 | +function wl_transition_post_status($new_status, $old_status, $post) { |
|
| 26 | 26 | |
| 27 | 27 | // wl_write_log( "wl_transition_post_status [ new status :: $new_status ][ old status :: $old_status ][ post ID :: $post->ID ]" ); |
| 28 | 28 | |
| 29 | 29 | // transition from *published* to any other status: delete the post. |
| 30 | - if ( 'publish' === $old_status && 'publish' !== $new_status ) { |
|
| 30 | + if ('publish' === $old_status && 'publish' !== $new_status) { |
|
| 31 | 31 | // Delete the post from the triple store. |
| 32 | - rl_delete_post( $post ); |
|
| 32 | + rl_delete_post($post); |
|
| 33 | 33 | |
| 34 | 34 | // Remove all relation instances for the current post from `wl_relation_instances`. |
| 35 | - wl_core_delete_relation_instances( $post->ID ); |
|
| 35 | + wl_core_delete_relation_instances($post->ID); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | // when a post is published, then all the referenced entities must be published. |
| 39 | - if ( 'publish' !== $old_status && 'publish' === $new_status ) { |
|
| 40 | - foreach ( wl_core_get_related_entity_ids( $post->ID ) as $entity_id ) { |
|
| 41 | - wl_update_post_status( $entity_id, 'publish' ); |
|
| 39 | + if ('publish' !== $old_status && 'publish' === $new_status) { |
|
| 40 | + foreach (wl_core_get_related_entity_ids($post->ID) as $entity_id) { |
|
| 41 | + wl_update_post_status($entity_id, 'publish'); |
|
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | // hook save events. |
| 47 | -add_action( 'transition_post_status', 'wl_transition_post_status', 10, 3 ); |
|
| 47 | +add_action('transition_post_status', 'wl_transition_post_status', 10, 3); |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -52,12 +52,12 @@ discard block |
||
| 52 | 52 | * |
| 53 | 53 | * @param array|int $post An array of post data |
| 54 | 54 | */ |
| 55 | -function rl_delete_post( $post ) { |
|
| 55 | +function rl_delete_post($post) { |
|
| 56 | 56 | |
| 57 | - $post_id = ( is_numeric( $post ) ? $post : $post->ID ); |
|
| 57 | + $post_id = (is_numeric($post) ? $post : $post->ID); |
|
| 58 | 58 | |
| 59 | 59 | // Remove the post. |
| 60 | - Wordlift_Linked_Data_Service::get_instance()->remove( $post_id ); |
|
| 60 | + Wordlift_Linked_Data_Service::get_instance()->remove($post_id); |
|
| 61 | 61 | |
| 62 | 62 | } |
| 63 | 63 | |
@@ -67,37 +67,37 @@ discard block |
||
| 67 | 67 | * @param int $post_id The post ID |
| 68 | 68 | * @param string $status The new status |
| 69 | 69 | */ |
| 70 | -function wl_update_post_status( $post_id, $status ) { |
|
| 70 | +function wl_update_post_status($post_id, $status) { |
|
| 71 | 71 | |
| 72 | - wl_write_log( "wl_update_post_status [ post ID :: $post_id ][ status :: $status ]" ); |
|
| 72 | + wl_write_log("wl_update_post_status [ post ID :: $post_id ][ status :: $status ]"); |
|
| 73 | 73 | |
| 74 | 74 | global $wpdb; |
| 75 | 75 | |
| 76 | - if ( ! $post = get_post( $post_id ) ) { |
|
| 76 | + if ( ! $post = get_post($post_id)) { |
|
| 77 | 77 | return; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - if ( $status === $post->post_status ) { |
|
| 80 | + if ($status === $post->post_status) { |
|
| 81 | 81 | return; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - wl_write_log( "wl_update_post_status, old and new post status do not match [ post ID :: $post_id ][ new status :: $status ][ old status :: $post->post_status ]." ); |
|
| 84 | + wl_write_log("wl_update_post_status, old and new post status do not match [ post ID :: $post_id ][ new status :: $status ][ old status :: $post->post_status ]."); |
|
| 85 | 85 | |
| 86 | - $wpdb->update( $wpdb->posts, array( 'post_status' => $status ), array( 'ID' => $post->ID ) ); |
|
| 86 | + $wpdb->update($wpdb->posts, array('post_status' => $status), array('ID' => $post->ID)); |
|
| 87 | 87 | |
| 88 | - clean_post_cache( $post->ID ); |
|
| 88 | + clean_post_cache($post->ID); |
|
| 89 | 89 | |
| 90 | 90 | $old_status = $post->post_status; |
| 91 | 91 | $post->post_status = $status; |
| 92 | 92 | |
| 93 | - wp_transition_post_status( $status, $old_status, $post ); |
|
| 93 | + wp_transition_post_status($status, $old_status, $post); |
|
| 94 | 94 | |
| 95 | 95 | /** This action is documented in wp-includes/post.php */ |
| 96 | - do_action( 'edit_post', $post->ID, $post ); |
|
| 96 | + do_action('edit_post', $post->ID, $post); |
|
| 97 | 97 | /** This action is documented in wp-includes/post.php */ |
| 98 | - do_action( "save_post_{$post->post_type}", $post->ID, $post, true ); |
|
| 98 | + do_action("save_post_{$post->post_type}", $post->ID, $post, true); |
|
| 99 | 99 | /** This action is documented in wp-includes/post.php */ |
| 100 | - do_action( 'wl_linked_data_save_post', $post->ID ); |
|
| 100 | + do_action('wl_linked_data_save_post', $post->ID); |
|
| 101 | 101 | /** This action is documented in wp-includes/post.php */ |
| 102 | - do_action( 'wp_insert_post', $post->ID, $post, true ); |
|
| 102 | + do_action('wp_insert_post', $post->ID, $post, true); |
|
| 103 | 103 | } |
@@ -16,42 +16,42 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | class Wordlift_Admin_Term_Adapter { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * The meta key holding the entity id. |
|
| 21 | - * |
|
| 22 | - * @since 3.20.0 |
|
| 23 | - */ |
|
| 24 | - const META_KEY = '_wl_entity_id'; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Create a Wordlift_Admin_Term_Adapter instance. |
|
| 28 | - * |
|
| 29 | - * @since 3.20.0 |
|
| 30 | - */ |
|
| 31 | - public function __construct() { |
|
| 32 | - |
|
| 33 | - add_action( 'registered_taxonomy', array( $this, 'add_action', ) ); |
|
| 34 | - add_action( 'edit_term', array( $this, 'edit_term', ), 10, 3 ); |
|
| 35 | - |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Add the form fields to the entity edit screen. |
|
| 40 | - * |
|
| 41 | - * @since 3.20.0 |
|
| 42 | - * |
|
| 43 | - * @param object $tag Current taxonomy term object. |
|
| 44 | - * @param string $taxonomy Current taxonomy slug. |
|
| 45 | - */ |
|
| 46 | - public function edit_form_fields( $tag, $taxonomy ) { |
|
| 47 | - |
|
| 48 | - // Enqueue the JavaScript app. |
|
| 49 | - wp_enqueue_script( 'wl-term', plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/term.js', array( 'wp-util', ), Wordlift::get_instance()->get_version(), true ); |
|
| 50 | - wp_enqueue_style( 'wl-term', plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/term.css', array(), Wordlift::get_instance()->get_version() ); |
|
| 51 | - |
|
| 52 | - $values = get_term_meta( $tag->term_id, self::META_KEY ); |
|
| 53 | - |
|
| 54 | - ?> |
|
| 19 | + /** |
|
| 20 | + * The meta key holding the entity id. |
|
| 21 | + * |
|
| 22 | + * @since 3.20.0 |
|
| 23 | + */ |
|
| 24 | + const META_KEY = '_wl_entity_id'; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Create a Wordlift_Admin_Term_Adapter instance. |
|
| 28 | + * |
|
| 29 | + * @since 3.20.0 |
|
| 30 | + */ |
|
| 31 | + public function __construct() { |
|
| 32 | + |
|
| 33 | + add_action( 'registered_taxonomy', array( $this, 'add_action', ) ); |
|
| 34 | + add_action( 'edit_term', array( $this, 'edit_term', ), 10, 3 ); |
|
| 35 | + |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Add the form fields to the entity edit screen. |
|
| 40 | + * |
|
| 41 | + * @since 3.20.0 |
|
| 42 | + * |
|
| 43 | + * @param object $tag Current taxonomy term object. |
|
| 44 | + * @param string $taxonomy Current taxonomy slug. |
|
| 45 | + */ |
|
| 46 | + public function edit_form_fields( $tag, $taxonomy ) { |
|
| 47 | + |
|
| 48 | + // Enqueue the JavaScript app. |
|
| 49 | + wp_enqueue_script( 'wl-term', plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/term.js', array( 'wp-util', ), Wordlift::get_instance()->get_version(), true ); |
|
| 50 | + wp_enqueue_style( 'wl-term', plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/term.css', array(), Wordlift::get_instance()->get_version() ); |
|
| 51 | + |
|
| 52 | + $values = get_term_meta( $tag->term_id, self::META_KEY ); |
|
| 53 | + |
|
| 54 | + ?> |
|
| 55 | 55 | <tr class="form-field term-name-wrap"> |
| 56 | 56 | <th scope="row"><label for="wl-entity-id"><?php _ex( 'Entity', 'term entity', 'wordlift' ); ?></label></th> |
| 57 | 57 | <td> |
@@ -63,65 +63,65 @@ discard block |
||
| 63 | 63 | </td> |
| 64 | 64 | </tr> |
| 65 | 65 | <?php |
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Bind the new fields to the edit term screen. |
|
| 70 | - * |
|
| 71 | - * @since 3.20.0 |
|
| 72 | - * |
|
| 73 | - * @param string $taxonomy The taxonomy name. |
|
| 74 | - */ |
|
| 75 | - public function add_action( $taxonomy ) { |
|
| 76 | - |
|
| 77 | - add_action( "{$taxonomy}_edit_form_fields", array( $this, 'edit_form_fields' ), 10, 2 ); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Hook to the edit term to handle our own custom fields. |
|
| 82 | - * |
|
| 83 | - * @since 3.20.0 |
|
| 84 | - * |
|
| 85 | - * @param int $term_id The term id. |
|
| 86 | - * @param int $tt_id The term taxonomy id. |
|
| 87 | - * @param string $taxonomy The taxonomy. |
|
| 88 | - */ |
|
| 89 | - public function edit_term( $term_id, $tt_id, $taxonomy ) { |
|
| 90 | - |
|
| 91 | - // Bail if the action isn't related to the term currently being edited. |
|
| 92 | - if ( ! isset( $_POST['tag_ID'] ) || $term_id !== (int) (int) $_POST['tag_ID'] ) { |
|
| 93 | - return; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - // Delete. |
|
| 97 | - if ( ! isset( $_POST['wl_entity_id'] ) || ! is_array( $_POST['wl_entity_id'] ) || empty( $_POST['wl_entity_id'] ) ) { |
|
| 98 | - delete_term_meta( $term_id, self::META_KEY ); |
|
| 99 | - |
|
| 100 | - return; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // Update. |
|
| 104 | - // |
|
| 105 | - // Only use mb_* functions when mbstring is available. |
|
| 106 | - // |
|
| 107 | - // See https://github.com/insideout10/wordlift-plugin/issues/693. |
|
| 108 | - if ( extension_loaded( 'mbstring' ) ) { |
|
| 109 | - mb_regex_encoding( 'UTF-8' ); |
|
| 110 | - |
|
| 111 | - $merged = array_reduce( (array) $_POST['wl_entity_id'], function ( $carry, $item ) { |
|
| 112 | - return array_merge( $carry, mb_split( "\x{2063}", wp_unslash( $item ) ) ); |
|
| 113 | - }, array() ); |
|
| 114 | - } else { |
|
| 115 | - $merged = array_reduce( (array) $_POST['wl_entity_id'], function ( $carry, $item ) { |
|
| 116 | - return array_merge( $carry, preg_split( "/\x{2063}/u", wp_unslash( $item ) ) ); |
|
| 117 | - }, array() ); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - delete_term_meta( $term_id, self::META_KEY ); |
|
| 121 | - foreach ( array_unique( array_filter( $merged ) ) as $single ) { |
|
| 122 | - add_term_meta( $term_id, self::META_KEY, $single ); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - } |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Bind the new fields to the edit term screen. |
|
| 70 | + * |
|
| 71 | + * @since 3.20.0 |
|
| 72 | + * |
|
| 73 | + * @param string $taxonomy The taxonomy name. |
|
| 74 | + */ |
|
| 75 | + public function add_action( $taxonomy ) { |
|
| 76 | + |
|
| 77 | + add_action( "{$taxonomy}_edit_form_fields", array( $this, 'edit_form_fields' ), 10, 2 ); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Hook to the edit term to handle our own custom fields. |
|
| 82 | + * |
|
| 83 | + * @since 3.20.0 |
|
| 84 | + * |
|
| 85 | + * @param int $term_id The term id. |
|
| 86 | + * @param int $tt_id The term taxonomy id. |
|
| 87 | + * @param string $taxonomy The taxonomy. |
|
| 88 | + */ |
|
| 89 | + public function edit_term( $term_id, $tt_id, $taxonomy ) { |
|
| 90 | + |
|
| 91 | + // Bail if the action isn't related to the term currently being edited. |
|
| 92 | + if ( ! isset( $_POST['tag_ID'] ) || $term_id !== (int) (int) $_POST['tag_ID'] ) { |
|
| 93 | + return; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + // Delete. |
|
| 97 | + if ( ! isset( $_POST['wl_entity_id'] ) || ! is_array( $_POST['wl_entity_id'] ) || empty( $_POST['wl_entity_id'] ) ) { |
|
| 98 | + delete_term_meta( $term_id, self::META_KEY ); |
|
| 99 | + |
|
| 100 | + return; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // Update. |
|
| 104 | + // |
|
| 105 | + // Only use mb_* functions when mbstring is available. |
|
| 106 | + // |
|
| 107 | + // See https://github.com/insideout10/wordlift-plugin/issues/693. |
|
| 108 | + if ( extension_loaded( 'mbstring' ) ) { |
|
| 109 | + mb_regex_encoding( 'UTF-8' ); |
|
| 110 | + |
|
| 111 | + $merged = array_reduce( (array) $_POST['wl_entity_id'], function ( $carry, $item ) { |
|
| 112 | + return array_merge( $carry, mb_split( "\x{2063}", wp_unslash( $item ) ) ); |
|
| 113 | + }, array() ); |
|
| 114 | + } else { |
|
| 115 | + $merged = array_reduce( (array) $_POST['wl_entity_id'], function ( $carry, $item ) { |
|
| 116 | + return array_merge( $carry, preg_split( "/\x{2063}/u", wp_unslash( $item ) ) ); |
|
| 117 | + }, array() ); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + delete_term_meta( $term_id, self::META_KEY ); |
|
| 121 | + foreach ( array_unique( array_filter( $merged ) ) as $single ) { |
|
| 122 | + add_term_meta( $term_id, self::META_KEY, $single ); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | 127 | } |
| 128 | 128 | \ No newline at end of file |
@@ -30,8 +30,8 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | public function __construct() { |
| 32 | 32 | |
| 33 | - add_action( 'registered_taxonomy', array( $this, 'add_action', ) ); |
|
| 34 | - add_action( 'edit_term', array( $this, 'edit_term', ), 10, 3 ); |
|
| 33 | + add_action('registered_taxonomy', array($this, 'add_action',)); |
|
| 34 | + add_action('edit_term', array($this, 'edit_term',), 10, 3); |
|
| 35 | 35 | |
| 36 | 36 | } |
| 37 | 37 | |
@@ -43,23 +43,23 @@ discard block |
||
| 43 | 43 | * @param object $tag Current taxonomy term object. |
| 44 | 44 | * @param string $taxonomy Current taxonomy slug. |
| 45 | 45 | */ |
| 46 | - public function edit_form_fields( $tag, $taxonomy ) { |
|
| 46 | + public function edit_form_fields($tag, $taxonomy) { |
|
| 47 | 47 | |
| 48 | 48 | // Enqueue the JavaScript app. |
| 49 | - wp_enqueue_script( 'wl-term', plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/term.js', array( 'wp-util', ), Wordlift::get_instance()->get_version(), true ); |
|
| 50 | - wp_enqueue_style( 'wl-term', plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/term.css', array(), Wordlift::get_instance()->get_version() ); |
|
| 49 | + wp_enqueue_script('wl-term', plugin_dir_url(dirname(__FILE__)).'js/dist/term.js', array('wp-util',), Wordlift::get_instance()->get_version(), true); |
|
| 50 | + wp_enqueue_style('wl-term', plugin_dir_url(dirname(__FILE__)).'js/dist/term.css', array(), Wordlift::get_instance()->get_version()); |
|
| 51 | 51 | |
| 52 | - $values = get_term_meta( $tag->term_id, self::META_KEY ); |
|
| 52 | + $values = get_term_meta($tag->term_id, self::META_KEY); |
|
| 53 | 53 | |
| 54 | 54 | ?> |
| 55 | 55 | <tr class="form-field term-name-wrap"> |
| 56 | - <th scope="row"><label for="wl-entity-id"><?php _ex( 'Entity', 'term entity', 'wordlift' ); ?></label></th> |
|
| 56 | + <th scope="row"><label for="wl-entity-id"><?php _ex('Entity', 'term entity', 'wordlift'); ?></label></th> |
|
| 57 | 57 | <td> |
| 58 | - <?php foreach ( $values as $value ) { ?> |
|
| 59 | - <input type="text" name="wl_entity_id[]" value="<?php echo esc_attr( $value ); ?>"/> |
|
| 58 | + <?php foreach ($values as $value) { ?> |
|
| 59 | + <input type="text" name="wl_entity_id[]" value="<?php echo esc_attr($value); ?>"/> |
|
| 60 | 60 | <?php } ?> |
| 61 | 61 | <div id="wl-term-entity-id"></div> |
| 62 | - <p class="description"><?php _e( 'The entity bound to the term.', 'wordlift' ); ?></p> |
|
| 62 | + <p class="description"><?php _e('The entity bound to the term.', 'wordlift'); ?></p> |
|
| 63 | 63 | </td> |
| 64 | 64 | </tr> |
| 65 | 65 | <?php |
@@ -72,9 +72,9 @@ discard block |
||
| 72 | 72 | * |
| 73 | 73 | * @param string $taxonomy The taxonomy name. |
| 74 | 74 | */ |
| 75 | - public function add_action( $taxonomy ) { |
|
| 75 | + public function add_action($taxonomy) { |
|
| 76 | 76 | |
| 77 | - add_action( "{$taxonomy}_edit_form_fields", array( $this, 'edit_form_fields' ), 10, 2 ); |
|
| 77 | + add_action("{$taxonomy}_edit_form_fields", array($this, 'edit_form_fields'), 10, 2); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -86,16 +86,16 @@ discard block |
||
| 86 | 86 | * @param int $tt_id The term taxonomy id. |
| 87 | 87 | * @param string $taxonomy The taxonomy. |
| 88 | 88 | */ |
| 89 | - public function edit_term( $term_id, $tt_id, $taxonomy ) { |
|
| 89 | + public function edit_term($term_id, $tt_id, $taxonomy) { |
|
| 90 | 90 | |
| 91 | 91 | // Bail if the action isn't related to the term currently being edited. |
| 92 | - if ( ! isset( $_POST['tag_ID'] ) || $term_id !== (int) (int) $_POST['tag_ID'] ) { |
|
| 92 | + if ( ! isset($_POST['tag_ID']) || $term_id !== (int) (int) $_POST['tag_ID']) { |
|
| 93 | 93 | return; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | // Delete. |
| 97 | - if ( ! isset( $_POST['wl_entity_id'] ) || ! is_array( $_POST['wl_entity_id'] ) || empty( $_POST['wl_entity_id'] ) ) { |
|
| 98 | - delete_term_meta( $term_id, self::META_KEY ); |
|
| 97 | + if ( ! isset($_POST['wl_entity_id']) || ! is_array($_POST['wl_entity_id']) || empty($_POST['wl_entity_id'])) { |
|
| 98 | + delete_term_meta($term_id, self::META_KEY); |
|
| 99 | 99 | |
| 100 | 100 | return; |
| 101 | 101 | } |
@@ -105,21 +105,21 @@ discard block |
||
| 105 | 105 | // Only use mb_* functions when mbstring is available. |
| 106 | 106 | // |
| 107 | 107 | // See https://github.com/insideout10/wordlift-plugin/issues/693. |
| 108 | - if ( extension_loaded( 'mbstring' ) ) { |
|
| 109 | - mb_regex_encoding( 'UTF-8' ); |
|
| 108 | + if (extension_loaded('mbstring')) { |
|
| 109 | + mb_regex_encoding('UTF-8'); |
|
| 110 | 110 | |
| 111 | - $merged = array_reduce( (array) $_POST['wl_entity_id'], function ( $carry, $item ) { |
|
| 112 | - return array_merge( $carry, mb_split( "\x{2063}", wp_unslash( $item ) ) ); |
|
| 113 | - }, array() ); |
|
| 111 | + $merged = array_reduce((array) $_POST['wl_entity_id'], function($carry, $item) { |
|
| 112 | + return array_merge($carry, mb_split("\x{2063}", wp_unslash($item))); |
|
| 113 | + }, array()); |
|
| 114 | 114 | } else { |
| 115 | - $merged = array_reduce( (array) $_POST['wl_entity_id'], function ( $carry, $item ) { |
|
| 116 | - return array_merge( $carry, preg_split( "/\x{2063}/u", wp_unslash( $item ) ) ); |
|
| 117 | - }, array() ); |
|
| 115 | + $merged = array_reduce((array) $_POST['wl_entity_id'], function($carry, $item) { |
|
| 116 | + return array_merge($carry, preg_split("/\x{2063}/u", wp_unslash($item))); |
|
| 117 | + }, array()); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - delete_term_meta( $term_id, self::META_KEY ); |
|
| 121 | - foreach ( array_unique( array_filter( $merged ) ) as $single ) { |
|
| 122 | - add_term_meta( $term_id, self::META_KEY, $single ); |
|
| 120 | + delete_term_meta($term_id, self::META_KEY); |
|
| 121 | + foreach (array_unique(array_filter($merged)) as $single) { |
|
| 122 | + add_term_meta($term_id, self::META_KEY, $single); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | } |
@@ -17,40 +17,40 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | class Wordlift_Admin_Schemaorg_Taxonomy_Metabox { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Render the metabox. |
|
| 22 | - * |
|
| 23 | - * @since 3.20.0 |
|
| 24 | - */ |
|
| 25 | - public static function render() { |
|
| 20 | + /** |
|
| 21 | + * Render the metabox. |
|
| 22 | + * |
|
| 23 | + * @since 3.20.0 |
|
| 24 | + */ |
|
| 25 | + public static function render() { |
|
| 26 | 26 | |
| 27 | - Wordlift_Admin_Schemaorg_Taxonomy_Metabox::post_categories_meta_box( get_post(), array( |
|
| 28 | - 'args' => |
|
| 29 | - array( 'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ), |
|
| 30 | - ) ); |
|
| 27 | + Wordlift_Admin_Schemaorg_Taxonomy_Metabox::post_categories_meta_box( get_post(), array( |
|
| 28 | + 'args' => |
|
| 29 | + array( 'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ), |
|
| 30 | + ) ); |
|
| 31 | 31 | |
| 32 | - } |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * A function which resembles WordPress' own to display a metabox, but which customizes the output |
|
| 36 | - * to display the Schema.org classes tree. |
|
| 37 | - * |
|
| 38 | - * @since 3.20.0 |
|
| 39 | - * |
|
| 40 | - * @param WP_Post $post The {@link WP_Post} being edited. |
|
| 41 | - * @param array $box An array of arguments. |
|
| 42 | - */ |
|
| 43 | - private static function post_categories_meta_box( $post, $box ) { |
|
| 44 | - $defaults = array( 'taxonomy' => 'category' ); |
|
| 45 | - if ( ! isset( $box['args'] ) || ! is_array( $box['args'] ) ) { |
|
| 46 | - $args = array(); |
|
| 47 | - } else { |
|
| 48 | - $args = $box['args']; |
|
| 49 | - } |
|
| 50 | - $r = wp_parse_args( $args, $defaults ); |
|
| 51 | - $tax_name = esc_attr( $r['taxonomy'] ); |
|
| 52 | - $taxonomy = get_taxonomy( $r['taxonomy'] ); |
|
| 53 | - ?> |
|
| 34 | + /** |
|
| 35 | + * A function which resembles WordPress' own to display a metabox, but which customizes the output |
|
| 36 | + * to display the Schema.org classes tree. |
|
| 37 | + * |
|
| 38 | + * @since 3.20.0 |
|
| 39 | + * |
|
| 40 | + * @param WP_Post $post The {@link WP_Post} being edited. |
|
| 41 | + * @param array $box An array of arguments. |
|
| 42 | + */ |
|
| 43 | + private static function post_categories_meta_box( $post, $box ) { |
|
| 44 | + $defaults = array( 'taxonomy' => 'category' ); |
|
| 45 | + if ( ! isset( $box['args'] ) || ! is_array( $box['args'] ) ) { |
|
| 46 | + $args = array(); |
|
| 47 | + } else { |
|
| 48 | + $args = $box['args']; |
|
| 49 | + } |
|
| 50 | + $r = wp_parse_args( $args, $defaults ); |
|
| 51 | + $tax_name = esc_attr( $r['taxonomy'] ); |
|
| 52 | + $taxonomy = get_taxonomy( $r['taxonomy'] ); |
|
| 53 | + ?> |
|
| 54 | 54 | <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv"> |
| 55 | 55 | <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs"> |
| 56 | 56 | <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a> |
@@ -75,15 +75,15 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | <div id="<?php echo $tax_name; ?>-legacy" class="tabs-panel" style="display: none;"> |
| 77 | 77 | <?php |
| 78 | - $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']'; |
|
| 79 | - echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks. |
|
| 80 | - ?> |
|
| 78 | + $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']'; |
|
| 79 | + echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks. |
|
| 80 | + ?> |
|
| 81 | 81 | <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" |
| 82 | 82 | class="categorychecklist form-no-clear"> |
| 83 | 83 | <?php wp_terms_checklist( $post->ID, array( |
| 84 | - 'taxonomy' => $tax_name, |
|
| 85 | - 'popular_cats' => $popular_ids, |
|
| 86 | - ) ); ?> |
|
| 84 | + 'taxonomy' => $tax_name, |
|
| 85 | + 'popular_cats' => $popular_ids, |
|
| 86 | + ) ); ?> |
|
| 87 | 87 | </ul> |
| 88 | 88 | </div> |
| 89 | 89 | <?php if ( current_user_can( $taxonomy->cap->edit_terms ) ) : ?> |
@@ -91,9 +91,9 @@ discard block |
||
| 91 | 91 | <a id="<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" |
| 92 | 92 | class="taxonomy-add-new"> |
| 93 | 93 | <?php |
| 94 | - /* translators: %s: add new taxonomy label */ |
|
| 95 | - printf( __( '+ %s' ), $taxonomy->labels->add_new_item ); |
|
| 96 | - ?> |
|
| 94 | + /* translators: %s: add new taxonomy label */ |
|
| 95 | + printf( __( '+ %s' ), $taxonomy->labels->add_new_item ); |
|
| 96 | + ?> |
|
| 97 | 97 | </a> |
| 98 | 98 | <p id="<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child"> |
| 99 | 99 | <label class="screen-reader-text" |
@@ -106,43 +106,43 @@ discard block |
||
| 106 | 106 | <?php echo $taxonomy->labels->parent_item_colon; ?> |
| 107 | 107 | </label> |
| 108 | 108 | <?php |
| 109 | - $parent_dropdown_args = array( |
|
| 110 | - 'taxonomy' => $tax_name, |
|
| 111 | - 'hide_empty' => 0, |
|
| 112 | - 'name' => 'new' . $tax_name . '_parent', |
|
| 113 | - 'orderby' => 'name', |
|
| 114 | - 'hierarchical' => 1, |
|
| 115 | - 'show_option_none' => '— ' . $taxonomy->labels->parent_item . ' —', |
|
| 116 | - ); |
|
| 109 | + $parent_dropdown_args = array( |
|
| 110 | + 'taxonomy' => $tax_name, |
|
| 111 | + 'hide_empty' => 0, |
|
| 112 | + 'name' => 'new' . $tax_name . '_parent', |
|
| 113 | + 'orderby' => 'name', |
|
| 114 | + 'hierarchical' => 1, |
|
| 115 | + 'show_option_none' => '— ' . $taxonomy->labels->parent_item . ' —', |
|
| 116 | + ); |
|
| 117 | 117 | |
| 118 | - /** |
|
| 119 | - * Filters the arguments for the taxonomy parent dropdown on the Post Edit page. |
|
| 120 | - * |
|
| 121 | - * @since 4.4.0 |
|
| 122 | - * |
|
| 123 | - * @param array $parent_dropdown_args { |
|
| 124 | - * Optional. Array of arguments to generate parent dropdown. |
|
| 125 | - * |
|
| 126 | - * @type string $taxonomy Name of the taxonomy to retrieve. |
|
| 127 | - * @type bool $hide_if_empty True to skip generating markup if no |
|
| 128 | - * categories are found. Default 0. |
|
| 129 | - * @type string $name Value for the 'name' attribute |
|
| 130 | - * of the select element. |
|
| 131 | - * Default "new{$tax_name}_parent". |
|
| 132 | - * @type string $orderby Which column to use for ordering |
|
| 133 | - * terms. Default 'name'. |
|
| 134 | - * @type bool|int $hierarchical Whether to traverse the taxonomy |
|
| 135 | - * hierarchy. Default 1. |
|
| 136 | - * @type string $show_option_none Text to display for the "none" option. |
|
| 137 | - * Default "— {$parent} —", |
|
| 138 | - * where `$parent` is 'parent_item' |
|
| 139 | - * taxonomy label. |
|
| 140 | - * } |
|
| 141 | - */ |
|
| 142 | - $parent_dropdown_args = apply_filters( 'post_edit_category_parent_dropdown_args', $parent_dropdown_args ); |
|
| 118 | + /** |
|
| 119 | + * Filters the arguments for the taxonomy parent dropdown on the Post Edit page. |
|
| 120 | + * |
|
| 121 | + * @since 4.4.0 |
|
| 122 | + * |
|
| 123 | + * @param array $parent_dropdown_args { |
|
| 124 | + * Optional. Array of arguments to generate parent dropdown. |
|
| 125 | + * |
|
| 126 | + * @type string $taxonomy Name of the taxonomy to retrieve. |
|
| 127 | + * @type bool $hide_if_empty True to skip generating markup if no |
|
| 128 | + * categories are found. Default 0. |
|
| 129 | + * @type string $name Value for the 'name' attribute |
|
| 130 | + * of the select element. |
|
| 131 | + * Default "new{$tax_name}_parent". |
|
| 132 | + * @type string $orderby Which column to use for ordering |
|
| 133 | + * terms. Default 'name'. |
|
| 134 | + * @type bool|int $hierarchical Whether to traverse the taxonomy |
|
| 135 | + * hierarchy. Default 1. |
|
| 136 | + * @type string $show_option_none Text to display for the "none" option. |
|
| 137 | + * Default "— {$parent} —", |
|
| 138 | + * where `$parent` is 'parent_item' |
|
| 139 | + * taxonomy label. |
|
| 140 | + * } |
|
| 141 | + */ |
|
| 142 | + $parent_dropdown_args = apply_filters( 'post_edit_category_parent_dropdown_args', $parent_dropdown_args ); |
|
| 143 | 143 | |
| 144 | - wp_dropdown_categories( $parent_dropdown_args ); |
|
| 145 | - ?> |
|
| 144 | + wp_dropdown_categories( $parent_dropdown_args ); |
|
| 145 | + ?> |
|
| 146 | 146 | <input type="button" id="<?php echo $tax_name; ?>-add-submit" |
| 147 | 147 | data-wp-lists="add:<?php echo $tax_name; ?>checklist:<?php echo $tax_name; ?>-add" |
| 148 | 148 | class="button category-add-submit" |
@@ -154,6 +154,6 @@ discard block |
||
| 154 | 154 | <?php endif; ?> |
| 155 | 155 | </div> |
| 156 | 156 | <?php |
| 157 | - } |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | 159 | } |
@@ -24,10 +24,10 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | public static function render() { |
| 26 | 26 | |
| 27 | - Wordlift_Admin_Schemaorg_Taxonomy_Metabox::post_categories_meta_box( get_post(), array( |
|
| 27 | + Wordlift_Admin_Schemaorg_Taxonomy_Metabox::post_categories_meta_box(get_post(), array( |
|
| 28 | 28 | 'args' => |
| 29 | - array( 'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ), |
|
| 30 | - ) ); |
|
| 29 | + array('taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME), |
|
| 30 | + )); |
|
| 31 | 31 | |
| 32 | 32 | } |
| 33 | 33 | |
@@ -40,26 +40,26 @@ discard block |
||
| 40 | 40 | * @param WP_Post $post The {@link WP_Post} being edited. |
| 41 | 41 | * @param array $box An array of arguments. |
| 42 | 42 | */ |
| 43 | - private static function post_categories_meta_box( $post, $box ) { |
|
| 44 | - $defaults = array( 'taxonomy' => 'category' ); |
|
| 45 | - if ( ! isset( $box['args'] ) || ! is_array( $box['args'] ) ) { |
|
| 43 | + private static function post_categories_meta_box($post, $box) { |
|
| 44 | + $defaults = array('taxonomy' => 'category'); |
|
| 45 | + if ( ! isset($box['args']) || ! is_array($box['args'])) { |
|
| 46 | 46 | $args = array(); |
| 47 | 47 | } else { |
| 48 | 48 | $args = $box['args']; |
| 49 | 49 | } |
| 50 | - $r = wp_parse_args( $args, $defaults ); |
|
| 51 | - $tax_name = esc_attr( $r['taxonomy'] ); |
|
| 52 | - $taxonomy = get_taxonomy( $r['taxonomy'] ); |
|
| 50 | + $r = wp_parse_args($args, $defaults); |
|
| 51 | + $tax_name = esc_attr($r['taxonomy']); |
|
| 52 | + $taxonomy = get_taxonomy($r['taxonomy']); |
|
| 53 | 53 | ?> |
| 54 | 54 | <div id="taxonomy-<?php echo $tax_name; ?>" class="categorydiv"> |
| 55 | 55 | <ul id="<?php echo $tax_name; ?>-tabs" class="category-tabs"> |
| 56 | 56 | <li class="tabs"><a href="#<?php echo $tax_name; ?>-all"><?php echo $taxonomy->labels->all_items; ?></a> |
| 57 | 57 | </li> |
| 58 | 58 | <li><a |
| 59 | - href="#<?php echo $tax_name; ?>-pop"><?php echo esc_html( $taxonomy->labels->most_used ); ?></a> |
|
| 59 | + href="#<?php echo $tax_name; ?>-pop"><?php echo esc_html($taxonomy->labels->most_used); ?></a> |
|
| 60 | 60 | </li> |
| 61 | 61 | <li><a href="#<?php echo $tax_name; ?>-legacy"> |
| 62 | - <?php echo esc_html_x( 'A-Z', 'Entity Types metabox', 'wordlift' ); ?></a> |
|
| 62 | + <?php echo esc_html_x('A-Z', 'Entity Types metabox', 'wordlift'); ?></a> |
|
| 63 | 63 | </li> |
| 64 | 64 | </ul> |
| 65 | 65 | |
@@ -69,30 +69,30 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | <div id="<?php echo $tax_name; ?>-pop" class="tabs-panel" style="display: none;"> |
| 71 | 71 | <ul id="<?php echo $tax_name; ?>checklist-pop" class="categorychecklist form-no-clear"> |
| 72 | - <?php $popular_ids = wp_popular_terms_checklist( $tax_name ); ?> |
|
| 72 | + <?php $popular_ids = wp_popular_terms_checklist($tax_name); ?> |
|
| 73 | 73 | </ul> |
| 74 | 74 | </div> |
| 75 | 75 | |
| 76 | 76 | <div id="<?php echo $tax_name; ?>-legacy" class="tabs-panel" style="display: none;"> |
| 77 | 77 | <?php |
| 78 | - $name = ( $tax_name == 'category' ) ? 'post_category' : 'tax_input[' . $tax_name . ']'; |
|
| 78 | + $name = ($tax_name == 'category') ? 'post_category' : 'tax_input['.$tax_name.']'; |
|
| 79 | 79 | echo "<input type='hidden' name='{$name}[]' value='0' />"; // Allows for an empty term set to be sent. 0 is an invalid Term ID and will be ignored by empty() checks. |
| 80 | 80 | ?> |
| 81 | 81 | <ul id="<?php echo $tax_name; ?>checklist" data-wp-lists="list:<?php echo $tax_name; ?>" |
| 82 | 82 | class="categorychecklist form-no-clear"> |
| 83 | - <?php wp_terms_checklist( $post->ID, array( |
|
| 83 | + <?php wp_terms_checklist($post->ID, array( |
|
| 84 | 84 | 'taxonomy' => $tax_name, |
| 85 | 85 | 'popular_cats' => $popular_ids, |
| 86 | - ) ); ?> |
|
| 86 | + )); ?> |
|
| 87 | 87 | </ul> |
| 88 | 88 | </div> |
| 89 | - <?php if ( current_user_can( $taxonomy->cap->edit_terms ) ) : ?> |
|
| 89 | + <?php if (current_user_can($taxonomy->cap->edit_terms)) : ?> |
|
| 90 | 90 | <div id="<?php echo $tax_name; ?>-adder" class="wp-hidden-children"> |
| 91 | 91 | <a id="<?php echo $tax_name; ?>-add-toggle" href="#<?php echo $tax_name; ?>-add" |
| 92 | 92 | class="taxonomy-add-new"> |
| 93 | 93 | <?php |
| 94 | 94 | /* translators: %s: add new taxonomy label */ |
| 95 | - printf( __( '+ %s' ), $taxonomy->labels->add_new_item ); |
|
| 95 | + printf(__('+ %s'), $taxonomy->labels->add_new_item); |
|
| 96 | 96 | ?> |
| 97 | 97 | </a> |
| 98 | 98 | <p id="<?php echo $tax_name; ?>-add" class="category-add wp-hidden-child"> |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | for="new<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->add_new_item; ?></label> |
| 101 | 101 | <input type="text" name="new<?php echo $tax_name; ?>" id="new<?php echo $tax_name; ?>" |
| 102 | 102 | class="form-required form-input-tip" |
| 103 | - value="<?php echo esc_attr( $taxonomy->labels->new_item_name ); ?>" |
|
| 103 | + value="<?php echo esc_attr($taxonomy->labels->new_item_name); ?>" |
|
| 104 | 104 | aria-required="true"/> |
| 105 | 105 | <label class="screen-reader-text" for="new<?php echo $tax_name; ?>_parent"> |
| 106 | 106 | <?php echo $taxonomy->labels->parent_item_colon; ?> |
@@ -109,10 +109,10 @@ discard block |
||
| 109 | 109 | $parent_dropdown_args = array( |
| 110 | 110 | 'taxonomy' => $tax_name, |
| 111 | 111 | 'hide_empty' => 0, |
| 112 | - 'name' => 'new' . $tax_name . '_parent', |
|
| 112 | + 'name' => 'new'.$tax_name.'_parent', |
|
| 113 | 113 | 'orderby' => 'name', |
| 114 | 114 | 'hierarchical' => 1, |
| 115 | - 'show_option_none' => '— ' . $taxonomy->labels->parent_item . ' —', |
|
| 115 | + 'show_option_none' => '— '.$taxonomy->labels->parent_item.' —', |
|
| 116 | 116 | ); |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -139,15 +139,15 @@ discard block |
||
| 139 | 139 | * taxonomy label. |
| 140 | 140 | * } |
| 141 | 141 | */ |
| 142 | - $parent_dropdown_args = apply_filters( 'post_edit_category_parent_dropdown_args', $parent_dropdown_args ); |
|
| 142 | + $parent_dropdown_args = apply_filters('post_edit_category_parent_dropdown_args', $parent_dropdown_args); |
|
| 143 | 143 | |
| 144 | - wp_dropdown_categories( $parent_dropdown_args ); |
|
| 144 | + wp_dropdown_categories($parent_dropdown_args); |
|
| 145 | 145 | ?> |
| 146 | 146 | <input type="button" id="<?php echo $tax_name; ?>-add-submit" |
| 147 | 147 | data-wp-lists="add:<?php echo $tax_name; ?>checklist:<?php echo $tax_name; ?>-add" |
| 148 | 148 | class="button category-add-submit" |
| 149 | - value="<?php echo esc_attr( $taxonomy->labels->add_new_item ); ?>"/> |
|
| 150 | - <?php wp_nonce_field( 'add-' . $tax_name, '_ajax_nonce-add-' . $tax_name, false ); ?> |
|
| 149 | + value="<?php echo esc_attr($taxonomy->labels->add_new_item); ?>"/> |
|
| 150 | + <?php wp_nonce_field('add-'.$tax_name, '_ajax_nonce-add-'.$tax_name, false); ?> |
|
| 151 | 151 | <span id="<?php echo $tax_name; ?>-ajax-response"></span> |
| 152 | 152 | </p> |
| 153 | 153 | </div> |
@@ -16,37 +16,37 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Wordlift_Admin_Mappings_Page extends Wordlift_Admin_Page { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * {@inheritdoc} |
|
| 21 | - */ |
|
| 22 | - function get_page_title() { |
|
| 19 | + /** |
|
| 20 | + * {@inheritdoc} |
|
| 21 | + */ |
|
| 22 | + function get_page_title() { |
|
| 23 | 23 | |
| 24 | - return __( 'Mappings', 'wordlift' ); |
|
| 25 | - } |
|
| 24 | + return __( 'Mappings', 'wordlift' ); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * {@inheritdoc} |
|
| 29 | - */ |
|
| 30 | - function get_menu_title() { |
|
| 27 | + /** |
|
| 28 | + * {@inheritdoc} |
|
| 29 | + */ |
|
| 30 | + function get_menu_title() { |
|
| 31 | 31 | |
| 32 | - return __( 'Mappings', 'wordlift' ); |
|
| 33 | - } |
|
| 32 | + return __( 'Mappings', 'wordlift' ); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * {@inheritdoc} |
|
| 37 | - */ |
|
| 38 | - function get_menu_slug() { |
|
| 35 | + /** |
|
| 36 | + * {@inheritdoc} |
|
| 37 | + */ |
|
| 38 | + function get_menu_slug() { |
|
| 39 | 39 | |
| 40 | - return 'wl_mappings'; |
|
| 41 | - } |
|
| 40 | + return 'wl_mappings'; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * {@inheritdoc} |
|
| 45 | - */ |
|
| 43 | + /** |
|
| 44 | + * {@inheritdoc} |
|
| 45 | + */ |
|
| 46 | 46 | |
| 47 | - function get_partial_name() { |
|
| 47 | + function get_partial_name() { |
|
| 48 | 48 | |
| 49 | - return 'wordlift-admin-mappings-page.php'; |
|
| 50 | - } |
|
| 49 | + return 'wordlift-admin-mappings-page.php'; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | 52 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | function get_page_title() { |
| 23 | 23 | |
| 24 | - return __( 'Mappings', 'wordlift' ); |
|
| 24 | + return __('Mappings', 'wordlift'); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | function get_menu_title() { |
| 31 | 31 | |
| 32 | - return __( 'Mappings', 'wordlift' ); |
|
| 32 | + return __('Mappings', 'wordlift'); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -22,314 +22,314 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class Wordlift_Admin { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * The ID of this plugin. |
|
| 27 | - * |
|
| 28 | - * @since 1.0.0 |
|
| 29 | - * @access private |
|
| 30 | - * @var string $plugin_name The ID of this plugin. |
|
| 31 | - */ |
|
| 32 | - private $plugin_name; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * The version of this plugin. |
|
| 36 | - * |
|
| 37 | - * @since 1.0.0 |
|
| 38 | - * @access private |
|
| 39 | - * @var string $version The current version of this plugin. |
|
| 40 | - */ |
|
| 41 | - private $version; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * The {@link Wordlift_Configuration_Service} instance. |
|
| 45 | - * |
|
| 46 | - * @since 3.14.0 |
|
| 47 | - * @access private |
|
| 48 | - * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance. |
|
| 49 | - */ |
|
| 50 | - private $configuration_service; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * The {@link Wordlift_User_Service} instance. |
|
| 54 | - * |
|
| 55 | - * @since 3.14.0 |
|
| 56 | - * @access private |
|
| 57 | - * @var \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
|
| 58 | - */ |
|
| 59 | - private $user_service; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * The {@link Wordlift_Batch_Operation_Ajax_Adapter} instance. |
|
| 63 | - * |
|
| 64 | - * @since 3.20.0 |
|
| 65 | - * @access private |
|
| 66 | - * @var \Wordlift_Batch_Operation_Ajax_Adapter $sync_batch_operation_ajax_adapter The {@link Wordlift_Batch_Operation_Ajax_Adapter} instance. |
|
| 67 | - */ |
|
| 68 | - private $sync_batch_operation_ajax_adapter; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * The singleton instance. |
|
| 72 | - * |
|
| 73 | - * @since 3.19.4 |
|
| 74 | - * @access private |
|
| 75 | - * @var Wordlift_Admin $instance The singleton instance. |
|
| 76 | - */ |
|
| 77 | - private static $instance; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Initialize the class and set its properties. |
|
| 81 | - * |
|
| 82 | - * @since 1.0.0 |
|
| 83 | - * |
|
| 84 | - * @param string $plugin_name The name of this plugin. |
|
| 85 | - * @param string $version The version of this plugin. |
|
| 86 | - * @param \Wordlift_Configuration_Service $configuration_service The configuration service. |
|
| 87 | - * @param \Wordlift_Notice_Service $notice_service The notice service. |
|
| 88 | - * @param \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
|
| 89 | - */ |
|
| 90 | - public function __construct( $plugin_name, $version, $configuration_service, $notice_service, $user_service ) { |
|
| 91 | - |
|
| 92 | - $this->plugin_name = $plugin_name; |
|
| 93 | - $this->version = $version; |
|
| 94 | - |
|
| 95 | - $this->configuration_service = $configuration_service; |
|
| 96 | - $this->user_service = $user_service; |
|
| 97 | - |
|
| 98 | - $dataset_uri = $configuration_service->get_dataset_uri(); |
|
| 99 | - $key = $configuration_service->get_key(); |
|
| 100 | - |
|
| 101 | - if ( empty( $dataset_uri ) ) { |
|
| 102 | - $settings_page = Wordlift_Admin_Settings_Page::get_instance(); |
|
| 103 | - if ( empty( $key ) ) { |
|
| 104 | - $error = sprintf( esc_html__( "WordLift's key isn't set, please open the %s to set WordLift's key.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' ); |
|
| 105 | - } else { |
|
| 106 | - $error = sprintf( esc_html__( "WordLift's dataset URI is not configured: please open the %s to set WordLift's key again.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' ); |
|
| 107 | - } |
|
| 108 | - $notice_service->add_error( $error ); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - // Load additional code if we're in the admin UI. |
|
| 112 | - if ( is_admin() ) { |
|
| 113 | - |
|
| 114 | - // Require the PHP files for the next code fragment. |
|
| 115 | - self::require_files(); |
|
| 116 | - |
|
| 117 | - new Wordlift_Dashboard_Latest_News(); |
|
| 118 | - |
|
| 119 | - // Search Rankings. |
|
| 120 | - $search_rankings_service = new Wordlift_Admin_Search_Rankings_Service( Wordlift_Api_Service::get_instance() ); |
|
| 121 | - new Wordlift_Admin_Search_Rankings_Ajax_Adapter( $search_rankings_service ); |
|
| 122 | - |
|
| 123 | - /* |
|
| 25 | + /** |
|
| 26 | + * The ID of this plugin. |
|
| 27 | + * |
|
| 28 | + * @since 1.0.0 |
|
| 29 | + * @access private |
|
| 30 | + * @var string $plugin_name The ID of this plugin. |
|
| 31 | + */ |
|
| 32 | + private $plugin_name; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * The version of this plugin. |
|
| 36 | + * |
|
| 37 | + * @since 1.0.0 |
|
| 38 | + * @access private |
|
| 39 | + * @var string $version The current version of this plugin. |
|
| 40 | + */ |
|
| 41 | + private $version; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * The {@link Wordlift_Configuration_Service} instance. |
|
| 45 | + * |
|
| 46 | + * @since 3.14.0 |
|
| 47 | + * @access private |
|
| 48 | + * @var \Wordlift_Configuration_Service $configuration_service The {@link Wordlift_Configuration_Service} instance. |
|
| 49 | + */ |
|
| 50 | + private $configuration_service; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * The {@link Wordlift_User_Service} instance. |
|
| 54 | + * |
|
| 55 | + * @since 3.14.0 |
|
| 56 | + * @access private |
|
| 57 | + * @var \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
|
| 58 | + */ |
|
| 59 | + private $user_service; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * The {@link Wordlift_Batch_Operation_Ajax_Adapter} instance. |
|
| 63 | + * |
|
| 64 | + * @since 3.20.0 |
|
| 65 | + * @access private |
|
| 66 | + * @var \Wordlift_Batch_Operation_Ajax_Adapter $sync_batch_operation_ajax_adapter The {@link Wordlift_Batch_Operation_Ajax_Adapter} instance. |
|
| 67 | + */ |
|
| 68 | + private $sync_batch_operation_ajax_adapter; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * The singleton instance. |
|
| 72 | + * |
|
| 73 | + * @since 3.19.4 |
|
| 74 | + * @access private |
|
| 75 | + * @var Wordlift_Admin $instance The singleton instance. |
|
| 76 | + */ |
|
| 77 | + private static $instance; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Initialize the class and set its properties. |
|
| 81 | + * |
|
| 82 | + * @since 1.0.0 |
|
| 83 | + * |
|
| 84 | + * @param string $plugin_name The name of this plugin. |
|
| 85 | + * @param string $version The version of this plugin. |
|
| 86 | + * @param \Wordlift_Configuration_Service $configuration_service The configuration service. |
|
| 87 | + * @param \Wordlift_Notice_Service $notice_service The notice service. |
|
| 88 | + * @param \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
|
| 89 | + */ |
|
| 90 | + public function __construct( $plugin_name, $version, $configuration_service, $notice_service, $user_service ) { |
|
| 91 | + |
|
| 92 | + $this->plugin_name = $plugin_name; |
|
| 93 | + $this->version = $version; |
|
| 94 | + |
|
| 95 | + $this->configuration_service = $configuration_service; |
|
| 96 | + $this->user_service = $user_service; |
|
| 97 | + |
|
| 98 | + $dataset_uri = $configuration_service->get_dataset_uri(); |
|
| 99 | + $key = $configuration_service->get_key(); |
|
| 100 | + |
|
| 101 | + if ( empty( $dataset_uri ) ) { |
|
| 102 | + $settings_page = Wordlift_Admin_Settings_Page::get_instance(); |
|
| 103 | + if ( empty( $key ) ) { |
|
| 104 | + $error = sprintf( esc_html__( "WordLift's key isn't set, please open the %s to set WordLift's key.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' ); |
|
| 105 | + } else { |
|
| 106 | + $error = sprintf( esc_html__( "WordLift's dataset URI is not configured: please open the %s to set WordLift's key again.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' ); |
|
| 107 | + } |
|
| 108 | + $notice_service->add_error( $error ); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + // Load additional code if we're in the admin UI. |
|
| 112 | + if ( is_admin() ) { |
|
| 113 | + |
|
| 114 | + // Require the PHP files for the next code fragment. |
|
| 115 | + self::require_files(); |
|
| 116 | + |
|
| 117 | + new Wordlift_Dashboard_Latest_News(); |
|
| 118 | + |
|
| 119 | + // Search Rankings. |
|
| 120 | + $search_rankings_service = new Wordlift_Admin_Search_Rankings_Service( Wordlift_Api_Service::get_instance() ); |
|
| 121 | + new Wordlift_Admin_Search_Rankings_Ajax_Adapter( $search_rankings_service ); |
|
| 122 | + |
|
| 123 | + /* |
|
| 124 | 124 | * Add support for `All Entity Types`. |
| 125 | 125 | * |
| 126 | 126 | * @since 3.20.0 |
| 127 | 127 | * |
| 128 | 128 | * @see https://github.com/insideout10/wordlift-plugin/issues/835 |
| 129 | 129 | */ |
| 130 | - if ( WL_ALL_ENTITY_TYPES ) { |
|
| 131 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-schemaorg-taxonomy-metabox.php'; |
|
| 132 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-schemaorg-property-metabox.php'; |
|
| 130 | + if ( WL_ALL_ENTITY_TYPES ) { |
|
| 131 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-schemaorg-taxonomy-metabox.php'; |
|
| 132 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-schemaorg-property-metabox.php'; |
|
| 133 | 133 | |
| 134 | - // new Wordlift_Admin_Schemaorg_Property_Metabox( Wordlift_Schemaorg_Property_Service::get_instance() ); |
|
| 135 | - /* |
|
| 134 | + // new Wordlift_Admin_Schemaorg_Property_Metabox( Wordlift_Schemaorg_Property_Service::get_instance() ); |
|
| 135 | + /* |
|
| 136 | 136 | * The `Mappings` admin page. |
| 137 | 137 | */ |
| 138 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-mappings-page.php'; |
|
| 139 | - new Wordlift_Admin_Mappings_Page(); |
|
| 138 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-mappings-page.php'; |
|
| 139 | + new Wordlift_Admin_Mappings_Page(); |
|
| 140 | 140 | |
| 141 | - /* |
|
| 141 | + /* |
|
| 142 | 142 | * Allow sync'ing the schema.org taxonomy with the schema.org json file. |
| 143 | 143 | * |
| 144 | 144 | * @since 3.20.0 |
| 145 | 145 | */ |
| 146 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/schemaorg/class-wordlift-schemaorg-sync-batch-operation.php'; |
|
| 146 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/schemaorg/class-wordlift-schemaorg-sync-batch-operation.php'; |
|
| 147 | 147 | |
| 148 | - $this->sync_batch_operation_ajax_adapter = new Wordlift_Batch_Operation_Ajax_Adapter( new Wordlift_Schemaorg_Sync_Batch_Operation(), 'wl_schemaorg_sync' ); |
|
| 148 | + $this->sync_batch_operation_ajax_adapter = new Wordlift_Batch_Operation_Ajax_Adapter( new Wordlift_Schemaorg_Sync_Batch_Operation(), 'wl_schemaorg_sync' ); |
|
| 149 | 149 | |
| 150 | - } |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - /* |
|
| 152 | + /* |
|
| 153 | 153 | * Add the {@link Wordlift_Admin_Term_Adapter}. |
| 154 | 154 | * |
| 155 | 155 | * @since 3.20.0 |
| 156 | 156 | */ |
| 157 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-term-adapter.php'; |
|
| 158 | - new Wordlift_Admin_Term_Adapter(); |
|
| 157 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-term-adapter.php'; |
|
| 158 | + new Wordlift_Admin_Term_Adapter(); |
|
| 159 | 159 | |
| 160 | - /* |
|
| 160 | + /* |
|
| 161 | 161 | * The new dashboard. |
| 162 | 162 | * |
| 163 | 163 | * @since 3.20.0 |
| 164 | 164 | * |
| 165 | 165 | * @see https://github.com/insideout10/wordlift-plugin/issues/879 |
| 166 | 166 | */ |
| 167 | - new Wordlift_Admin_Dashboard_V2( |
|
| 168 | - $search_rankings_service, |
|
| 169 | - Wordlift::get_instance()->get_dashboard_service(), |
|
| 170 | - Wordlift_Entity_Service::get_instance() |
|
| 171 | - ); |
|
| 172 | - new Wordlift_Admin_Not_Enriched_Filter(); |
|
| 173 | - |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - // Set the singleton instance. |
|
| 177 | - self::$instance = $this; |
|
| 178 | - |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Get the singleton instance. |
|
| 183 | - * |
|
| 184 | - * @since 3.19.4 |
|
| 185 | - * |
|
| 186 | - * @return \Wordlift_Admin The singleton instance. |
|
| 187 | - */ |
|
| 188 | - public static function get_instance() { |
|
| 189 | - |
|
| 190 | - return self::$instance; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Register the stylesheets for the admin area. |
|
| 195 | - * |
|
| 196 | - * @since 1.0.0 |
|
| 197 | - */ |
|
| 198 | - public function enqueue_styles() { |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * This function is provided for demonstration purposes only. |
|
| 202 | - * |
|
| 203 | - * An instance of this class should be passed to the run() function |
|
| 204 | - * defined in Wordlift_Loader as all of the hooks are defined |
|
| 205 | - * in that particular class. |
|
| 206 | - * |
|
| 207 | - * The Wordlift_Loader will then create the relationship |
|
| 208 | - * between the defined hooks and the functions defined in this |
|
| 209 | - * class. |
|
| 210 | - */ |
|
| 211 | - |
|
| 212 | - wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' ); |
|
| 213 | - |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * Register the JavaScript for the admin area. |
|
| 218 | - * |
|
| 219 | - * @since 1.0.0 |
|
| 220 | - */ |
|
| 221 | - public function enqueue_scripts() { |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * This function is provided for demonstration purposes only. |
|
| 225 | - * |
|
| 226 | - * An instance of this class should be passed to the run() function |
|
| 227 | - * defined in Wordlift_Loader as all of the hooks are defined |
|
| 228 | - * in that particular class. |
|
| 229 | - * |
|
| 230 | - * The Wordlift_Loader will then create the relationship |
|
| 231 | - * between the defined Wordlift_Schemaorg_Property_Servicehooks and the functions defined in this |
|
| 232 | - * class. |
|
| 233 | - */ |
|
| 234 | - |
|
| 235 | - // Enqueue the admin scripts. |
|
| 236 | - wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/1/admin.js', array( |
|
| 237 | - 'jquery', |
|
| 238 | - 'underscore', |
|
| 239 | - 'backbone', |
|
| 240 | - ), $this->version, false ); |
|
| 241 | - |
|
| 242 | - |
|
| 243 | - $can_edit_wordlift_entities = current_user_can( 'edit_wordlift_entities' ); |
|
| 244 | - |
|
| 245 | - /* |
|
| 167 | + new Wordlift_Admin_Dashboard_V2( |
|
| 168 | + $search_rankings_service, |
|
| 169 | + Wordlift::get_instance()->get_dashboard_service(), |
|
| 170 | + Wordlift_Entity_Service::get_instance() |
|
| 171 | + ); |
|
| 172 | + new Wordlift_Admin_Not_Enriched_Filter(); |
|
| 173 | + |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + // Set the singleton instance. |
|
| 177 | + self::$instance = $this; |
|
| 178 | + |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Get the singleton instance. |
|
| 183 | + * |
|
| 184 | + * @since 3.19.4 |
|
| 185 | + * |
|
| 186 | + * @return \Wordlift_Admin The singleton instance. |
|
| 187 | + */ |
|
| 188 | + public static function get_instance() { |
|
| 189 | + |
|
| 190 | + return self::$instance; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Register the stylesheets for the admin area. |
|
| 195 | + * |
|
| 196 | + * @since 1.0.0 |
|
| 197 | + */ |
|
| 198 | + public function enqueue_styles() { |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * This function is provided for demonstration purposes only. |
|
| 202 | + * |
|
| 203 | + * An instance of this class should be passed to the run() function |
|
| 204 | + * defined in Wordlift_Loader as all of the hooks are defined |
|
| 205 | + * in that particular class. |
|
| 206 | + * |
|
| 207 | + * The Wordlift_Loader will then create the relationship |
|
| 208 | + * between the defined hooks and the functions defined in this |
|
| 209 | + * class. |
|
| 210 | + */ |
|
| 211 | + |
|
| 212 | + wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' ); |
|
| 213 | + |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * Register the JavaScript for the admin area. |
|
| 218 | + * |
|
| 219 | + * @since 1.0.0 |
|
| 220 | + */ |
|
| 221 | + public function enqueue_scripts() { |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * This function is provided for demonstration purposes only. |
|
| 225 | + * |
|
| 226 | + * An instance of this class should be passed to the run() function |
|
| 227 | + * defined in Wordlift_Loader as all of the hooks are defined |
|
| 228 | + * in that particular class. |
|
| 229 | + * |
|
| 230 | + * The Wordlift_Loader will then create the relationship |
|
| 231 | + * between the defined Wordlift_Schemaorg_Property_Servicehooks and the functions defined in this |
|
| 232 | + * class. |
|
| 233 | + */ |
|
| 234 | + |
|
| 235 | + // Enqueue the admin scripts. |
|
| 236 | + wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/1/admin.js', array( |
|
| 237 | + 'jquery', |
|
| 238 | + 'underscore', |
|
| 239 | + 'backbone', |
|
| 240 | + ), $this->version, false ); |
|
| 241 | + |
|
| 242 | + |
|
| 243 | + $can_edit_wordlift_entities = current_user_can( 'edit_wordlift_entities' ); |
|
| 244 | + |
|
| 245 | + /* |
|
| 246 | 246 | * People that can create entities will see the scope set in the wp-config.php file (by default `cloud`). People |
| 247 | 247 | * that cannot edit create entities will always see the local entities. |
| 248 | 248 | * |
| 249 | 249 | * @see https://github.com/insideout10/wordlift-plugin/issues/839 |
| 250 | 250 | */ |
| 251 | - $autocomplete_scope = $can_edit_wordlift_entities ? WL_AUTOCOMPLETE_SCOPE : "local"; |
|
| 252 | - |
|
| 253 | - // Set the basic params. |
|
| 254 | - $params = array( |
|
| 255 | - // @todo scripts in admin should use wp.post. |
|
| 256 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 257 | - // @todo remove specific actions from settings. |
|
| 258 | - 'action' => 'entity_by_title', |
|
| 259 | - 'datasetUri' => $this->configuration_service->get_dataset_uri(), |
|
| 260 | - 'language' => $this->configuration_service->get_language_code(), |
|
| 261 | - 'link_by_default' => $this->configuration_service->is_link_by_default(), |
|
| 262 | - // Whether the current user is allowed to create new entities. |
|
| 263 | - // |
|
| 264 | - // @see https://github.com/insideout10/wordlift-plugin/issues/561 |
|
| 265 | - 'can_create_entities' => $can_edit_wordlift_entities ? 'yes' : 'no', |
|
| 266 | - 'l10n' => array( |
|
| 267 | - 'You already published an entity with the same name' => __( 'You already published an entity with the same name: ', 'wordlift' ), |
|
| 268 | - 'logo_selection_title' => __( 'WordLift Choose Logo', 'wordlift' ), |
|
| 269 | - 'logo_selection_button' => array( 'text' => __( 'Choose Logo', 'wordlift' ) ), |
|
| 270 | - 'Type at least 3 characters to search...' => _x( 'Type at least 3 characters to search...', 'Autocomplete Select', 'wordlift' ), |
|
| 271 | - 'No results found for your search.' => _x( 'No results found: try changing or removing some words.', 'Autocomplete Select', 'wordlift' ), |
|
| 272 | - 'Please wait while we look for entities in the linked data cloud...' => _x( 'Please wait while we look for entities in the linked data cloud...', 'Autocomplete Select', 'wordlift' ), |
|
| 273 | - ), |
|
| 274 | - 'wl_autocomplete_nonce' => wp_create_nonce( 'wordlift_autocomplete' ), |
|
| 275 | - 'autocomplete_scope' => $autocomplete_scope, |
|
| 276 | - /** |
|
| 277 | - * Allow 3rd parties to define the default editor id. This turns useful if 3rd parties load |
|
| 278 | - * or change the TinyMCE id. |
|
| 279 | - * |
|
| 280 | - * The editor id is currently referenced by `src/coffee/editpost-widget/app.services.EditorAdapter.coffee`. |
|
| 281 | - * |
|
| 282 | - * @since 3.19.4 |
|
| 283 | - * |
|
| 284 | - * @see https://github.com/insideout10/wordlift-plugin/issues/848 |
|
| 285 | - * |
|
| 286 | - * @param string $editor The default editor id, by default `content`. |
|
| 287 | - */ |
|
| 288 | - 'default_editor_id' => apply_filters( 'wl_default_editor_id', 'content' ), |
|
| 289 | - ); |
|
| 290 | - |
|
| 291 | - // Set post-related values if there's a current post. |
|
| 292 | - if ( null !== $post = $entity_being_edited = get_post() ) { |
|
| 293 | - |
|
| 294 | - $params['post_id'] = $entity_being_edited->ID; |
|
| 295 | - $entity_service = Wordlift_Entity_Service::get_instance(); |
|
| 296 | - $params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && $entity_service->is_entity( $post->ID ) && is_numeric( get_the_ID() ); |
|
| 297 | - // We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it |
|
| 298 | - // from the results, since we don't want the current entity to be discovered by the analysis. |
|
| 299 | - // |
|
| 300 | - // See https://github.com/insideout10/wordlift-plugin/issues/345 |
|
| 301 | - $params['itemId'] = $entity_service->get_uri( $entity_being_edited->ID ); |
|
| 302 | - $params['wl_schemaorg_property_nonce'] = wp_create_nonce( 'wl_schemaorg_property' ); |
|
| 303 | - |
|
| 304 | - /* |
|
| 251 | + $autocomplete_scope = $can_edit_wordlift_entities ? WL_AUTOCOMPLETE_SCOPE : "local"; |
|
| 252 | + |
|
| 253 | + // Set the basic params. |
|
| 254 | + $params = array( |
|
| 255 | + // @todo scripts in admin should use wp.post. |
|
| 256 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 257 | + // @todo remove specific actions from settings. |
|
| 258 | + 'action' => 'entity_by_title', |
|
| 259 | + 'datasetUri' => $this->configuration_service->get_dataset_uri(), |
|
| 260 | + 'language' => $this->configuration_service->get_language_code(), |
|
| 261 | + 'link_by_default' => $this->configuration_service->is_link_by_default(), |
|
| 262 | + // Whether the current user is allowed to create new entities. |
|
| 263 | + // |
|
| 264 | + // @see https://github.com/insideout10/wordlift-plugin/issues/561 |
|
| 265 | + 'can_create_entities' => $can_edit_wordlift_entities ? 'yes' : 'no', |
|
| 266 | + 'l10n' => array( |
|
| 267 | + 'You already published an entity with the same name' => __( 'You already published an entity with the same name: ', 'wordlift' ), |
|
| 268 | + 'logo_selection_title' => __( 'WordLift Choose Logo', 'wordlift' ), |
|
| 269 | + 'logo_selection_button' => array( 'text' => __( 'Choose Logo', 'wordlift' ) ), |
|
| 270 | + 'Type at least 3 characters to search...' => _x( 'Type at least 3 characters to search...', 'Autocomplete Select', 'wordlift' ), |
|
| 271 | + 'No results found for your search.' => _x( 'No results found: try changing or removing some words.', 'Autocomplete Select', 'wordlift' ), |
|
| 272 | + 'Please wait while we look for entities in the linked data cloud...' => _x( 'Please wait while we look for entities in the linked data cloud...', 'Autocomplete Select', 'wordlift' ), |
|
| 273 | + ), |
|
| 274 | + 'wl_autocomplete_nonce' => wp_create_nonce( 'wordlift_autocomplete' ), |
|
| 275 | + 'autocomplete_scope' => $autocomplete_scope, |
|
| 276 | + /** |
|
| 277 | + * Allow 3rd parties to define the default editor id. This turns useful if 3rd parties load |
|
| 278 | + * or change the TinyMCE id. |
|
| 279 | + * |
|
| 280 | + * The editor id is currently referenced by `src/coffee/editpost-widget/app.services.EditorAdapter.coffee`. |
|
| 281 | + * |
|
| 282 | + * @since 3.19.4 |
|
| 283 | + * |
|
| 284 | + * @see https://github.com/insideout10/wordlift-plugin/issues/848 |
|
| 285 | + * |
|
| 286 | + * @param string $editor The default editor id, by default `content`. |
|
| 287 | + */ |
|
| 288 | + 'default_editor_id' => apply_filters( 'wl_default_editor_id', 'content' ), |
|
| 289 | + ); |
|
| 290 | + |
|
| 291 | + // Set post-related values if there's a current post. |
|
| 292 | + if ( null !== $post = $entity_being_edited = get_post() ) { |
|
| 293 | + |
|
| 294 | + $params['post_id'] = $entity_being_edited->ID; |
|
| 295 | + $entity_service = Wordlift_Entity_Service::get_instance(); |
|
| 296 | + $params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && $entity_service->is_entity( $post->ID ) && is_numeric( get_the_ID() ); |
|
| 297 | + // We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it |
|
| 298 | + // from the results, since we don't want the current entity to be discovered by the analysis. |
|
| 299 | + // |
|
| 300 | + // See https://github.com/insideout10/wordlift-plugin/issues/345 |
|
| 301 | + $params['itemId'] = $entity_service->get_uri( $entity_being_edited->ID ); |
|
| 302 | + $params['wl_schemaorg_property_nonce'] = wp_create_nonce( 'wl_schemaorg_property' ); |
|
| 303 | + |
|
| 304 | + /* |
|
| 305 | 305 | * Add the `properties` if `WL_ALL_ENTITY_TYPES` is enabled. |
| 306 | 306 | * |
| 307 | 307 | * @see https://github.com/insideout10/wordlift-plugin/issues/835 |
| 308 | 308 | */ |
| 309 | - if ( WL_ALL_ENTITY_TYPES ) { |
|
| 310 | - $params['properties'] = Wordlift_Schemaorg_Property_Service::get_instance()->get_all( $post->ID ); |
|
| 311 | - } |
|
| 309 | + if ( WL_ALL_ENTITY_TYPES ) { |
|
| 310 | + $params['properties'] = Wordlift_Schemaorg_Property_Service::get_instance()->get_all( $post->ID ); |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - } |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | - // Finally output the params as `wlSettings` for JavaScript code. |
|
| 316 | - wp_localize_script( $this->plugin_name, 'wlSettings', apply_filters( 'wl_admin_settings', $params ) ); |
|
| 315 | + // Finally output the params as `wlSettings` for JavaScript code. |
|
| 316 | + wp_localize_script( $this->plugin_name, 'wlSettings', apply_filters( 'wl_admin_settings', $params ) ); |
|
| 317 | 317 | |
| 318 | - } |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - /** |
|
| 321 | - * Require files needed for the Admin UI. |
|
| 322 | - * |
|
| 323 | - * @since 3.20.0 |
|
| 324 | - */ |
|
| 325 | - private static function require_files() { |
|
| 320 | + /** |
|
| 321 | + * Require files needed for the Admin UI. |
|
| 322 | + * |
|
| 323 | + * @since 3.20.0 |
|
| 324 | + */ |
|
| 325 | + private static function require_files() { |
|
| 326 | 326 | |
| 327 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard-latest-news.php'; |
|
| 328 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-search-rankings-service.php'; |
|
| 329 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-search-rankings-ajax-adapter.php'; |
|
| 330 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard-v2.php'; |
|
| 331 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-not-enriched-filter.php'; |
|
| 327 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard-latest-news.php'; |
|
| 328 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-search-rankings-service.php'; |
|
| 329 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-search-rankings-ajax-adapter.php'; |
|
| 330 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard-v2.php'; |
|
| 331 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-not-enriched-filter.php'; |
|
| 332 | 332 | |
| 333 | - } |
|
| 333 | + } |
|
| 334 | 334 | |
| 335 | 335 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * @param \Wordlift_Notice_Service $notice_service The notice service. |
| 88 | 88 | * @param \Wordlift_User_Service $user_service The {@link Wordlift_User_Service} instance. |
| 89 | 89 | */ |
| 90 | - public function __construct( $plugin_name, $version, $configuration_service, $notice_service, $user_service ) { |
|
| 90 | + public function __construct($plugin_name, $version, $configuration_service, $notice_service, $user_service) { |
|
| 91 | 91 | |
| 92 | 92 | $this->plugin_name = $plugin_name; |
| 93 | 93 | $this->version = $version; |
@@ -98,18 +98,18 @@ discard block |
||
| 98 | 98 | $dataset_uri = $configuration_service->get_dataset_uri(); |
| 99 | 99 | $key = $configuration_service->get_key(); |
| 100 | 100 | |
| 101 | - if ( empty( $dataset_uri ) ) { |
|
| 101 | + if (empty($dataset_uri)) { |
|
| 102 | 102 | $settings_page = Wordlift_Admin_Settings_Page::get_instance(); |
| 103 | - if ( empty( $key ) ) { |
|
| 104 | - $error = sprintf( esc_html__( "WordLift's key isn't set, please open the %s to set WordLift's key.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' ); |
|
| 103 | + if (empty($key)) { |
|
| 104 | + $error = sprintf(esc_html__("WordLift's key isn't set, please open the %s to set WordLift's key.", 'wordlift'), '<a href="'.$settings_page->get_url().'">'.esc_html__('settings page', 'wordlift').'</a>'); |
|
| 105 | 105 | } else { |
| 106 | - $error = sprintf( esc_html__( "WordLift's dataset URI is not configured: please open the %s to set WordLift's key again.", 'wordlift' ), '<a href="' . $settings_page->get_url() . '">' . esc_html__( 'settings page', 'wordlift' ) . '</a>' ); |
|
| 106 | + $error = sprintf(esc_html__("WordLift's dataset URI is not configured: please open the %s to set WordLift's key again.", 'wordlift'), '<a href="'.$settings_page->get_url().'">'.esc_html__('settings page', 'wordlift').'</a>'); |
|
| 107 | 107 | } |
| 108 | - $notice_service->add_error( $error ); |
|
| 108 | + $notice_service->add_error($error); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | // Load additional code if we're in the admin UI. |
| 112 | - if ( is_admin() ) { |
|
| 112 | + if (is_admin()) { |
|
| 113 | 113 | |
| 114 | 114 | // Require the PHP files for the next code fragment. |
| 115 | 115 | self::require_files(); |
@@ -117,8 +117,8 @@ discard block |
||
| 117 | 117 | new Wordlift_Dashboard_Latest_News(); |
| 118 | 118 | |
| 119 | 119 | // Search Rankings. |
| 120 | - $search_rankings_service = new Wordlift_Admin_Search_Rankings_Service( Wordlift_Api_Service::get_instance() ); |
|
| 121 | - new Wordlift_Admin_Search_Rankings_Ajax_Adapter( $search_rankings_service ); |
|
| 120 | + $search_rankings_service = new Wordlift_Admin_Search_Rankings_Service(Wordlift_Api_Service::get_instance()); |
|
| 121 | + new Wordlift_Admin_Search_Rankings_Ajax_Adapter($search_rankings_service); |
|
| 122 | 122 | |
| 123 | 123 | /* |
| 124 | 124 | * Add support for `All Entity Types`. |
@@ -127,15 +127,15 @@ discard block |
||
| 127 | 127 | * |
| 128 | 128 | * @see https://github.com/insideout10/wordlift-plugin/issues/835 |
| 129 | 129 | */ |
| 130 | - if ( WL_ALL_ENTITY_TYPES ) { |
|
| 131 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-schemaorg-taxonomy-metabox.php'; |
|
| 132 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-schemaorg-property-metabox.php'; |
|
| 130 | + if (WL_ALL_ENTITY_TYPES) { |
|
| 131 | + require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-schemaorg-taxonomy-metabox.php'; |
|
| 132 | + require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-schemaorg-property-metabox.php'; |
|
| 133 | 133 | |
| 134 | 134 | // new Wordlift_Admin_Schemaorg_Property_Metabox( Wordlift_Schemaorg_Property_Service::get_instance() ); |
| 135 | 135 | /* |
| 136 | 136 | * The `Mappings` admin page. |
| 137 | 137 | */ |
| 138 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-mappings-page.php'; |
|
| 138 | + require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-mappings-page.php'; |
|
| 139 | 139 | new Wordlift_Admin_Mappings_Page(); |
| 140 | 140 | |
| 141 | 141 | /* |
@@ -143,9 +143,9 @@ discard block |
||
| 143 | 143 | * |
| 144 | 144 | * @since 3.20.0 |
| 145 | 145 | */ |
| 146 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/schemaorg/class-wordlift-schemaorg-sync-batch-operation.php'; |
|
| 146 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/schemaorg/class-wordlift-schemaorg-sync-batch-operation.php'; |
|
| 147 | 147 | |
| 148 | - $this->sync_batch_operation_ajax_adapter = new Wordlift_Batch_Operation_Ajax_Adapter( new Wordlift_Schemaorg_Sync_Batch_Operation(), 'wl_schemaorg_sync' ); |
|
| 148 | + $this->sync_batch_operation_ajax_adapter = new Wordlift_Batch_Operation_Ajax_Adapter(new Wordlift_Schemaorg_Sync_Batch_Operation(), 'wl_schemaorg_sync'); |
|
| 149 | 149 | |
| 150 | 150 | } |
| 151 | 151 | |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * |
| 155 | 155 | * @since 3.20.0 |
| 156 | 156 | */ |
| 157 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-term-adapter.php'; |
|
| 157 | + require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-term-adapter.php'; |
|
| 158 | 158 | new Wordlift_Admin_Term_Adapter(); |
| 159 | 159 | |
| 160 | 160 | /* |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | * class. |
| 210 | 210 | */ |
| 211 | 211 | |
| 212 | - wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/wordlift-admin.css', array(), $this->version, 'all' ); |
|
| 212 | + wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__).'css/wordlift-admin.css', array(), $this->version, 'all'); |
|
| 213 | 213 | |
| 214 | 214 | } |
| 215 | 215 | |
@@ -233,14 +233,14 @@ discard block |
||
| 233 | 233 | */ |
| 234 | 234 | |
| 235 | 235 | // Enqueue the admin scripts. |
| 236 | - wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/1/admin.js', array( |
|
| 236 | + wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__).'js/1/admin.js', array( |
|
| 237 | 237 | 'jquery', |
| 238 | 238 | 'underscore', |
| 239 | 239 | 'backbone', |
| 240 | - ), $this->version, false ); |
|
| 240 | + ), $this->version, false); |
|
| 241 | 241 | |
| 242 | 242 | |
| 243 | - $can_edit_wordlift_entities = current_user_can( 'edit_wordlift_entities' ); |
|
| 243 | + $can_edit_wordlift_entities = current_user_can('edit_wordlift_entities'); |
|
| 244 | 244 | |
| 245 | 245 | /* |
| 246 | 246 | * People that can create entities will see the scope set in the wp-config.php file (by default `cloud`). People |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | // Set the basic params. |
| 254 | 254 | $params = array( |
| 255 | 255 | // @todo scripts in admin should use wp.post. |
| 256 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 256 | + 'ajax_url' => admin_url('admin-ajax.php'), |
|
| 257 | 257 | // @todo remove specific actions from settings. |
| 258 | 258 | 'action' => 'entity_by_title', |
| 259 | 259 | 'datasetUri' => $this->configuration_service->get_dataset_uri(), |
@@ -264,14 +264,14 @@ discard block |
||
| 264 | 264 | // @see https://github.com/insideout10/wordlift-plugin/issues/561 |
| 265 | 265 | 'can_create_entities' => $can_edit_wordlift_entities ? 'yes' : 'no', |
| 266 | 266 | 'l10n' => array( |
| 267 | - 'You already published an entity with the same name' => __( 'You already published an entity with the same name: ', 'wordlift' ), |
|
| 268 | - 'logo_selection_title' => __( 'WordLift Choose Logo', 'wordlift' ), |
|
| 269 | - 'logo_selection_button' => array( 'text' => __( 'Choose Logo', 'wordlift' ) ), |
|
| 270 | - 'Type at least 3 characters to search...' => _x( 'Type at least 3 characters to search...', 'Autocomplete Select', 'wordlift' ), |
|
| 271 | - 'No results found for your search.' => _x( 'No results found: try changing or removing some words.', 'Autocomplete Select', 'wordlift' ), |
|
| 272 | - 'Please wait while we look for entities in the linked data cloud...' => _x( 'Please wait while we look for entities in the linked data cloud...', 'Autocomplete Select', 'wordlift' ), |
|
| 267 | + 'You already published an entity with the same name' => __('You already published an entity with the same name: ', 'wordlift'), |
|
| 268 | + 'logo_selection_title' => __('WordLift Choose Logo', 'wordlift'), |
|
| 269 | + 'logo_selection_button' => array('text' => __('Choose Logo', 'wordlift')), |
|
| 270 | + 'Type at least 3 characters to search...' => _x('Type at least 3 characters to search...', 'Autocomplete Select', 'wordlift'), |
|
| 271 | + 'No results found for your search.' => _x('No results found: try changing or removing some words.', 'Autocomplete Select', 'wordlift'), |
|
| 272 | + 'Please wait while we look for entities in the linked data cloud...' => _x('Please wait while we look for entities in the linked data cloud...', 'Autocomplete Select', 'wordlift'), |
|
| 273 | 273 | ), |
| 274 | - 'wl_autocomplete_nonce' => wp_create_nonce( 'wordlift_autocomplete' ), |
|
| 274 | + 'wl_autocomplete_nonce' => wp_create_nonce('wordlift_autocomplete'), |
|
| 275 | 275 | 'autocomplete_scope' => $autocomplete_scope, |
| 276 | 276 | /** |
| 277 | 277 | * Allow 3rd parties to define the default editor id. This turns useful if 3rd parties load |
@@ -285,35 +285,35 @@ discard block |
||
| 285 | 285 | * |
| 286 | 286 | * @param string $editor The default editor id, by default `content`. |
| 287 | 287 | */ |
| 288 | - 'default_editor_id' => apply_filters( 'wl_default_editor_id', 'content' ), |
|
| 288 | + 'default_editor_id' => apply_filters('wl_default_editor_id', 'content'), |
|
| 289 | 289 | ); |
| 290 | 290 | |
| 291 | 291 | // Set post-related values if there's a current post. |
| 292 | - if ( null !== $post = $entity_being_edited = get_post() ) { |
|
| 292 | + if (null !== $post = $entity_being_edited = get_post()) { |
|
| 293 | 293 | |
| 294 | 294 | $params['post_id'] = $entity_being_edited->ID; |
| 295 | 295 | $entity_service = Wordlift_Entity_Service::get_instance(); |
| 296 | - $params['entityBeingEdited'] = isset( $entity_being_edited->post_type ) && $entity_service->is_entity( $post->ID ) && is_numeric( get_the_ID() ); |
|
| 296 | + $params['entityBeingEdited'] = isset($entity_being_edited->post_type) && $entity_service->is_entity($post->ID) && is_numeric(get_the_ID()); |
|
| 297 | 297 | // We add the `itemId` here to give a chance to the analysis to use it in order to tell WLS to exclude it |
| 298 | 298 | // from the results, since we don't want the current entity to be discovered by the analysis. |
| 299 | 299 | // |
| 300 | 300 | // See https://github.com/insideout10/wordlift-plugin/issues/345 |
| 301 | - $params['itemId'] = $entity_service->get_uri( $entity_being_edited->ID ); |
|
| 302 | - $params['wl_schemaorg_property_nonce'] = wp_create_nonce( 'wl_schemaorg_property' ); |
|
| 301 | + $params['itemId'] = $entity_service->get_uri($entity_being_edited->ID); |
|
| 302 | + $params['wl_schemaorg_property_nonce'] = wp_create_nonce('wl_schemaorg_property'); |
|
| 303 | 303 | |
| 304 | 304 | /* |
| 305 | 305 | * Add the `properties` if `WL_ALL_ENTITY_TYPES` is enabled. |
| 306 | 306 | * |
| 307 | 307 | * @see https://github.com/insideout10/wordlift-plugin/issues/835 |
| 308 | 308 | */ |
| 309 | - if ( WL_ALL_ENTITY_TYPES ) { |
|
| 310 | - $params['properties'] = Wordlift_Schemaorg_Property_Service::get_instance()->get_all( $post->ID ); |
|
| 309 | + if (WL_ALL_ENTITY_TYPES) { |
|
| 310 | + $params['properties'] = Wordlift_Schemaorg_Property_Service::get_instance()->get_all($post->ID); |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | // Finally output the params as `wlSettings` for JavaScript code. |
| 316 | - wp_localize_script( $this->plugin_name, 'wlSettings', apply_filters( 'wl_admin_settings', $params ) ); |
|
| 316 | + wp_localize_script($this->plugin_name, 'wlSettings', apply_filters('wl_admin_settings', $params)); |
|
| 317 | 317 | |
| 318 | 318 | } |
| 319 | 319 | |
@@ -324,11 +324,11 @@ discard block |
||
| 324 | 324 | */ |
| 325 | 325 | private static function require_files() { |
| 326 | 326 | |
| 327 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard-latest-news.php'; |
|
| 328 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-search-rankings-service.php'; |
|
| 329 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-search-rankings-ajax-adapter.php'; |
|
| 330 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard-v2.php'; |
|
| 331 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-not-enriched-filter.php'; |
|
| 327 | + require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-dashboard-latest-news.php'; |
|
| 328 | + require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-search-rankings-service.php'; |
|
| 329 | + require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-search-rankings-ajax-adapter.php'; |
|
| 330 | + require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-dashboard-v2.php'; |
|
| 331 | + require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-not-enriched-filter.php'; |
|
| 332 | 332 | |
| 333 | 333 | } |
| 334 | 334 | |
@@ -16,56 +16,56 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Wordlift_Admin_Search_Rankings_Page extends Wordlift_Admin_Page { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * We decide whether to load this page from {@link Wordlift} if the user subscription is editorial or business. |
|
| 21 | - * |
|
| 22 | - * @since 3.20.0 |
|
| 23 | - */ |
|
| 24 | - public function __construct() { |
|
| 25 | - // Do nothing. We need this because the parent class calls the `admin_menu` hook. |
|
| 26 | - } |
|
| 19 | + /** |
|
| 20 | + * We decide whether to load this page from {@link Wordlift} if the user subscription is editorial or business. |
|
| 21 | + * |
|
| 22 | + * @since 3.20.0 |
|
| 23 | + */ |
|
| 24 | + public function __construct() { |
|
| 25 | + // Do nothing. We need this because the parent class calls the `admin_menu` hook. |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @inheritdoc |
|
| 30 | - */ |
|
| 31 | - function get_page_title() { |
|
| 28 | + /** |
|
| 29 | + * @inheritdoc |
|
| 30 | + */ |
|
| 31 | + function get_page_title() { |
|
| 32 | 32 | |
| 33 | - return _x( 'Search Rankings', 'Search Rankings', 'wordlift' ); |
|
| 34 | - } |
|
| 33 | + return _x( 'Search Rankings', 'Search Rankings', 'wordlift' ); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @inheritdoc |
|
| 38 | - */ |
|
| 39 | - function get_menu_title() { |
|
| 36 | + /** |
|
| 37 | + * @inheritdoc |
|
| 38 | + */ |
|
| 39 | + function get_menu_title() { |
|
| 40 | 40 | |
| 41 | - return _x( 'Search Rankings', 'Search Rankings', 'wordlift' ); |
|
| 42 | - } |
|
| 41 | + return _x( 'Search Rankings', 'Search Rankings', 'wordlift' ); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @inheritdoc |
|
| 46 | - */ |
|
| 47 | - function get_menu_slug() { |
|
| 44 | + /** |
|
| 45 | + * @inheritdoc |
|
| 46 | + */ |
|
| 47 | + function get_menu_slug() { |
|
| 48 | 48 | |
| 49 | - return 'wl_search_rankings'; |
|
| 50 | - } |
|
| 49 | + return 'wl_search_rankings'; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @inheritdoc |
|
| 54 | - */ |
|
| 55 | - function get_partial_name() { |
|
| 52 | + /** |
|
| 53 | + * @inheritdoc |
|
| 54 | + */ |
|
| 55 | + function get_partial_name() { |
|
| 56 | 56 | |
| 57 | - return 'wordlift-admin-search-rankings.php'; |
|
| 58 | - } |
|
| 57 | + return 'wordlift-admin-search-rankings.php'; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @inheritdoc |
|
| 62 | - */ |
|
| 63 | - public function enqueue_scripts() { |
|
| 64 | - parent::enqueue_scripts(); |
|
| 60 | + /** |
|
| 61 | + * @inheritdoc |
|
| 62 | + */ |
|
| 63 | + public function enqueue_scripts() { |
|
| 64 | + parent::enqueue_scripts(); |
|
| 65 | 65 | |
| 66 | - wp_enqueue_script( 'wl-admin-search-rankings', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/search-rankings.js', array(), Wordlift::get_instance()->get_version() ); |
|
| 67 | - wp_enqueue_style( 'wl-admin-search-rankings', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/search-rankings.css', array(), Wordlift::get_instance()->get_version() ); |
|
| 66 | + wp_enqueue_script( 'wl-admin-search-rankings', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/search-rankings.js', array(), Wordlift::get_instance()->get_version() ); |
|
| 67 | + wp_enqueue_style( 'wl-admin-search-rankings', plugin_dir_url( dirname( __FILE__ ) ) . 'admin/js/1/search-rankings.css', array(), Wordlift::get_instance()->get_version() ); |
|
| 68 | 68 | |
| 69 | - } |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | 71 | } |
@@ -18,141 +18,141 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | abstract class Wordlift_Admin_Page { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Define the {@link Wordlift_Admin_Page} constructor. |
|
| 23 | - * |
|
| 24 | - * @since 3.20.0 |
|
| 25 | - */ |
|
| 26 | - public function __construct() { |
|
| 27 | - |
|
| 28 | - add_action( 'admin_menu', array( $this, 'admin_menu' ), 10, 0 ); |
|
| 29 | - |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Get the parent slug. |
|
| 34 | - * |
|
| 35 | - * @since 3.11.0 |
|
| 36 | - * |
|
| 37 | - * @return string The parent slug (default 'wl_admin_menu'). |
|
| 38 | - */ |
|
| 39 | - protected function get_parent_slug() { |
|
| 40 | - |
|
| 41 | - return 'wl_admin_menu'; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Get the required capability. |
|
| 46 | - * |
|
| 47 | - * @since 3.11.0 |
|
| 48 | - * |
|
| 49 | - * @return string The capability (default 'manage_options'). |
|
| 50 | - */ |
|
| 51 | - protected function get_capability() { |
|
| 52 | - |
|
| 53 | - return 'manage_options'; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Get the page title. Will be translated. |
|
| 58 | - * |
|
| 59 | - * @since 3.11.0 |
|
| 60 | - * |
|
| 61 | - * @return string The page title. |
|
| 62 | - */ |
|
| 63 | - abstract function get_page_title(); |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Get the menu title. Will be translated. |
|
| 67 | - * |
|
| 68 | - * @since 3.11.0 |
|
| 69 | - * |
|
| 70 | - * @return string The menu title. |
|
| 71 | - */ |
|
| 72 | - abstract function get_menu_title(); |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Get the menu slug. |
|
| 76 | - * |
|
| 77 | - * @since 3.11.0 |
|
| 78 | - * |
|
| 79 | - * @return string The menu slug. |
|
| 80 | - */ |
|
| 81 | - abstract function get_menu_slug(); |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Get the page url. |
|
| 85 | - * |
|
| 86 | - * @since 3.14.0 |
|
| 87 | - * |
|
| 88 | - * @return string The escaped url of the admin page |
|
| 89 | - */ |
|
| 90 | - function get_url() { |
|
| 91 | - |
|
| 92 | - // ideally should have used menu_page_url, but it is loaded later than some usages. |
|
| 93 | - $url = admin_url( 'admin.php?page=' . $this->get_menu_slug() ); |
|
| 94 | - |
|
| 95 | - return esc_url( $url ); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Get the partial file name, used in the {@link render} function. |
|
| 100 | - * |
|
| 101 | - * @since 3.11.0 |
|
| 102 | - * |
|
| 103 | - * @return string The partial file name. |
|
| 104 | - */ |
|
| 105 | - abstract function get_partial_name(); |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * The `admin_menu` callback. Will call {@link add_submenu_page} to add the |
|
| 109 | - * page to the admin menu. |
|
| 110 | - * |
|
| 111 | - * @since 3.11.0 |
|
| 112 | - * |
|
| 113 | - * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. |
|
| 114 | - */ |
|
| 115 | - public function admin_menu() { |
|
| 116 | - |
|
| 117 | - // Add the sub-menu page. |
|
| 118 | - // |
|
| 119 | - // See http://codex.wordpress.org/Function_Reference/add_submenu_page |
|
| 120 | - $page = add_submenu_page( |
|
| 121 | - $this->get_parent_slug(), |
|
| 122 | - $this->get_page_title(), |
|
| 123 | - $this->get_menu_title(), |
|
| 124 | - $this->get_capability(), // The required capability, provided by the calling hook. |
|
| 125 | - $this->get_menu_slug(), |
|
| 126 | - array( $this, 'render' ) |
|
| 127 | - ); |
|
| 128 | - |
|
| 129 | - // Set a hook to enqueue scripts only when the settings page is displayed. |
|
| 130 | - add_action( 'admin_print_scripts-' . $page, array( |
|
| 131 | - $this, |
|
| 132 | - 'enqueue_scripts', |
|
| 133 | - ) ); |
|
| 134 | - |
|
| 135 | - // Finally return the page hook_suffix. |
|
| 136 | - return $page; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Enqueue scripts for the specific page. Subclasses can override this function |
|
| 141 | - * to provide their own styles/scripts. |
|
| 142 | - * |
|
| 143 | - * @since 3.11.0 |
|
| 144 | - */ |
|
| 145 | - public function enqueue_scripts() { |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Render the page. |
|
| 150 | - */ |
|
| 151 | - public function render() { |
|
| 152 | - |
|
| 153 | - // Include the partial. |
|
| 154 | - include( plugin_dir_path( __FILE__ ) . 'partials/' . $this->get_partial_name() ); |
|
| 155 | - |
|
| 156 | - } |
|
| 21 | + /** |
|
| 22 | + * Define the {@link Wordlift_Admin_Page} constructor. |
|
| 23 | + * |
|
| 24 | + * @since 3.20.0 |
|
| 25 | + */ |
|
| 26 | + public function __construct() { |
|
| 27 | + |
|
| 28 | + add_action( 'admin_menu', array( $this, 'admin_menu' ), 10, 0 ); |
|
| 29 | + |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Get the parent slug. |
|
| 34 | + * |
|
| 35 | + * @since 3.11.0 |
|
| 36 | + * |
|
| 37 | + * @return string The parent slug (default 'wl_admin_menu'). |
|
| 38 | + */ |
|
| 39 | + protected function get_parent_slug() { |
|
| 40 | + |
|
| 41 | + return 'wl_admin_menu'; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Get the required capability. |
|
| 46 | + * |
|
| 47 | + * @since 3.11.0 |
|
| 48 | + * |
|
| 49 | + * @return string The capability (default 'manage_options'). |
|
| 50 | + */ |
|
| 51 | + protected function get_capability() { |
|
| 52 | + |
|
| 53 | + return 'manage_options'; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Get the page title. Will be translated. |
|
| 58 | + * |
|
| 59 | + * @since 3.11.0 |
|
| 60 | + * |
|
| 61 | + * @return string The page title. |
|
| 62 | + */ |
|
| 63 | + abstract function get_page_title(); |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Get the menu title. Will be translated. |
|
| 67 | + * |
|
| 68 | + * @since 3.11.0 |
|
| 69 | + * |
|
| 70 | + * @return string The menu title. |
|
| 71 | + */ |
|
| 72 | + abstract function get_menu_title(); |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Get the menu slug. |
|
| 76 | + * |
|
| 77 | + * @since 3.11.0 |
|
| 78 | + * |
|
| 79 | + * @return string The menu slug. |
|
| 80 | + */ |
|
| 81 | + abstract function get_menu_slug(); |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Get the page url. |
|
| 85 | + * |
|
| 86 | + * @since 3.14.0 |
|
| 87 | + * |
|
| 88 | + * @return string The escaped url of the admin page |
|
| 89 | + */ |
|
| 90 | + function get_url() { |
|
| 91 | + |
|
| 92 | + // ideally should have used menu_page_url, but it is loaded later than some usages. |
|
| 93 | + $url = admin_url( 'admin.php?page=' . $this->get_menu_slug() ); |
|
| 94 | + |
|
| 95 | + return esc_url( $url ); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Get the partial file name, used in the {@link render} function. |
|
| 100 | + * |
|
| 101 | + * @since 3.11.0 |
|
| 102 | + * |
|
| 103 | + * @return string The partial file name. |
|
| 104 | + */ |
|
| 105 | + abstract function get_partial_name(); |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * The `admin_menu` callback. Will call {@link add_submenu_page} to add the |
|
| 109 | + * page to the admin menu. |
|
| 110 | + * |
|
| 111 | + * @since 3.11.0 |
|
| 112 | + * |
|
| 113 | + * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. |
|
| 114 | + */ |
|
| 115 | + public function admin_menu() { |
|
| 116 | + |
|
| 117 | + // Add the sub-menu page. |
|
| 118 | + // |
|
| 119 | + // See http://codex.wordpress.org/Function_Reference/add_submenu_page |
|
| 120 | + $page = add_submenu_page( |
|
| 121 | + $this->get_parent_slug(), |
|
| 122 | + $this->get_page_title(), |
|
| 123 | + $this->get_menu_title(), |
|
| 124 | + $this->get_capability(), // The required capability, provided by the calling hook. |
|
| 125 | + $this->get_menu_slug(), |
|
| 126 | + array( $this, 'render' ) |
|
| 127 | + ); |
|
| 128 | + |
|
| 129 | + // Set a hook to enqueue scripts only when the settings page is displayed. |
|
| 130 | + add_action( 'admin_print_scripts-' . $page, array( |
|
| 131 | + $this, |
|
| 132 | + 'enqueue_scripts', |
|
| 133 | + ) ); |
|
| 134 | + |
|
| 135 | + // Finally return the page hook_suffix. |
|
| 136 | + return $page; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Enqueue scripts for the specific page. Subclasses can override this function |
|
| 141 | + * to provide their own styles/scripts. |
|
| 142 | + * |
|
| 143 | + * @since 3.11.0 |
|
| 144 | + */ |
|
| 145 | + public function enqueue_scripts() { |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Render the page. |
|
| 150 | + */ |
|
| 151 | + public function render() { |
|
| 152 | + |
|
| 153 | + // Include the partial. |
|
| 154 | + include( plugin_dir_path( __FILE__ ) . 'partials/' . $this->get_partial_name() ); |
|
| 155 | + |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | 158 | } |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | public function __construct() { |
| 27 | 27 | |
| 28 | - add_action( 'admin_menu', array( $this, 'admin_menu' ), 10, 0 ); |
|
| 28 | + add_action('admin_menu', array($this, 'admin_menu'), 10, 0); |
|
| 29 | 29 | |
| 30 | 30 | } |
| 31 | 31 | |
@@ -90,9 +90,9 @@ discard block |
||
| 90 | 90 | function get_url() { |
| 91 | 91 | |
| 92 | 92 | // ideally should have used menu_page_url, but it is loaded later than some usages. |
| 93 | - $url = admin_url( 'admin.php?page=' . $this->get_menu_slug() ); |
|
| 93 | + $url = admin_url('admin.php?page='.$this->get_menu_slug()); |
|
| 94 | 94 | |
| 95 | - return esc_url( $url ); |
|
| 95 | + return esc_url($url); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -121,16 +121,16 @@ discard block |
||
| 121 | 121 | $this->get_parent_slug(), |
| 122 | 122 | $this->get_page_title(), |
| 123 | 123 | $this->get_menu_title(), |
| 124 | - $this->get_capability(), // The required capability, provided by the calling hook. |
|
| 124 | + $this->get_capability(), // The required capability, provided by the calling hook. |
|
| 125 | 125 | $this->get_menu_slug(), |
| 126 | - array( $this, 'render' ) |
|
| 126 | + array($this, 'render') |
|
| 127 | 127 | ); |
| 128 | 128 | |
| 129 | 129 | // Set a hook to enqueue scripts only when the settings page is displayed. |
| 130 | - add_action( 'admin_print_scripts-' . $page, array( |
|
| 130 | + add_action('admin_print_scripts-'.$page, array( |
|
| 131 | 131 | $this, |
| 132 | 132 | 'enqueue_scripts', |
| 133 | - ) ); |
|
| 133 | + )); |
|
| 134 | 134 | |
| 135 | 135 | // Finally return the page hook_suffix. |
| 136 | 136 | return $page; |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | public function render() { |
| 152 | 152 | |
| 153 | 153 | // Include the partial. |
| 154 | - include( plugin_dir_path( __FILE__ ) . 'partials/' . $this->get_partial_name() ); |
|
| 154 | + include(plugin_dir_path(__FILE__).'partials/'.$this->get_partial_name()); |
|
| 155 | 155 | |
| 156 | 156 | } |
| 157 | 157 | |
@@ -17,50 +17,50 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | <?php |
| 19 | 19 | |
| 20 | - $mappings = array_reduce( |
|
| 21 | - // The list of valid post types. |
|
| 22 | - Wordlift_Entity_Service::valid_entity_post_types(), |
|
| 20 | + $mappings = array_reduce( |
|
| 21 | + // The list of valid post types. |
|
| 22 | + Wordlift_Entity_Service::valid_entity_post_types(), |
|
| 23 | 23 | |
| 24 | - function ( $carry, $post_type ) use ( $mapping_service ) { |
|
| 25 | - $entity_types = array_filter( Wordlift_Entity_Type_Adapter::get_entity_types( $post_type ), |
|
| 26 | - function ( $item ) { |
|
| 27 | - return 'http://schema.org/Article' !== $item; |
|
| 28 | - } ); |
|
| 24 | + function ( $carry, $post_type ) use ( $mapping_service ) { |
|
| 25 | + $entity_types = array_filter( Wordlift_Entity_Type_Adapter::get_entity_types( $post_type ), |
|
| 26 | + function ( $item ) { |
|
| 27 | + return 'http://schema.org/Article' !== $item; |
|
| 28 | + } ); |
|
| 29 | 29 | |
| 30 | - if ( empty( $entity_types ) ) { |
|
| 31 | - return $carry; |
|
| 32 | - } |
|
| 30 | + if ( empty( $entity_types ) ) { |
|
| 31 | + return $carry; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - return $carry + array( |
|
| 35 | - $post_type => array( |
|
| 36 | - 'entity_types' => $entity_types, |
|
| 37 | - 'count' => $mapping_service->count( $post_type, $entity_types ), |
|
| 38 | - ), |
|
| 39 | - ); |
|
| 40 | - }, |
|
| 41 | - array() ); |
|
| 34 | + return $carry + array( |
|
| 35 | + $post_type => array( |
|
| 36 | + 'entity_types' => $entity_types, |
|
| 37 | + 'count' => $mapping_service->count( $post_type, $entity_types ), |
|
| 38 | + ), |
|
| 39 | + ); |
|
| 40 | + }, |
|
| 41 | + array() ); |
|
| 42 | 42 | |
| 43 | - $mappings['_nonce'] = wp_create_nonce( 'update_post_type_entity_types' ); |
|
| 43 | + $mappings['_nonce'] = wp_create_nonce( 'update_post_type_entity_types' ); |
|
| 44 | 44 | |
| 45 | 45 | |
| 46 | - $json = wp_json_encode( $mappings ); |
|
| 47 | - echo "<script type='application/javascript'>var wlMappings = $json;</script>"; |
|
| 46 | + $json = wp_json_encode( $mappings ); |
|
| 47 | + echo "<script type='application/javascript'>var wlMappings = $json;</script>"; |
|
| 48 | 48 | |
| 49 | - ?> |
|
| 49 | + ?> |
|
| 50 | 50 | |
| 51 | 51 | <?php |
| 52 | 52 | |
| 53 | - foreach ( $mappings as $key => $value ) { |
|
| 54 | - // Continue if this is the nonce. |
|
| 55 | - if ( '_nonce' == $key ) { |
|
| 56 | - continue; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - // Continue if the count isn't set or it's zero, i.e. no need to apply the taxonomy. |
|
| 60 | - if ( ! isset( $value['count'] ) || 0 === $value['count'] ) { |
|
| 61 | - continue; |
|
| 62 | - } |
|
| 63 | - ?> |
|
| 53 | + foreach ( $mappings as $key => $value ) { |
|
| 54 | + // Continue if this is the nonce. |
|
| 55 | + if ( '_nonce' == $key ) { |
|
| 56 | + continue; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + // Continue if the count isn't set or it's zero, i.e. no need to apply the taxonomy. |
|
| 60 | + if ( ! isset( $value['count'] ) || 0 === $value['count'] ) { |
|
| 61 | + continue; |
|
| 62 | + } |
|
| 63 | + ?> |
|
| 64 | 64 | <div class="post-type-to-entity-types"> |
| 65 | 65 | <button data-post-type="<?php echo esc_attr( $key ); ?>" |
| 66 | 66 | data-entity-types="<?php echo esc_attr( wp_json_encode( $value['entity_types'] ) ); ?>" |
@@ -68,9 +68,9 @@ discard block |
||
| 68 | 68 | <div><?php echo esc_html( $value['count'] ); ?></div> |
| 69 | 69 | </div> |
| 70 | 70 | <?php |
| 71 | - } |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - ?> |
|
| 73 | + ?> |
|
| 74 | 74 | |
| 75 | 75 | <div id="schemaorg-sync"> |
| 76 | 76 | <button>Sync Schema.org classes</button> |
@@ -6,13 +6,13 @@ discard block |
||
| 6 | 6 | * @package Wordlift |
| 7 | 7 | * @subpackage Wordlift/admin/partials |
| 8 | 8 | */ |
| 9 | -wp_enqueue_script( 'wp-util' ); |
|
| 9 | +wp_enqueue_script('wp-util'); |
|
| 10 | 10 | |
| 11 | 11 | $mapping_service = Wordlift_Mapping_Service::get_instance(); |
| 12 | 12 | ?> |
| 13 | 13 | <div id="wpbody-content" aria-label="Main content" tabindex="0"> |
| 14 | 14 | <div class="wrap"> |
| 15 | - <h1><?php echo esc_html__( 'Mappings', 'wordlift' ); ?></h1> |
|
| 15 | + <h1><?php echo esc_html__('Mappings', 'wordlift'); ?></h1> |
|
| 16 | 16 | </div> |
| 17 | 17 | |
| 18 | 18 | <?php |
@@ -21,51 +21,51 @@ discard block |
||
| 21 | 21 | // The list of valid post types. |
| 22 | 22 | Wordlift_Entity_Service::valid_entity_post_types(), |
| 23 | 23 | |
| 24 | - function ( $carry, $post_type ) use ( $mapping_service ) { |
|
| 25 | - $entity_types = array_filter( Wordlift_Entity_Type_Adapter::get_entity_types( $post_type ), |
|
| 26 | - function ( $item ) { |
|
| 24 | + function($carry, $post_type) use ($mapping_service) { |
|
| 25 | + $entity_types = array_filter(Wordlift_Entity_Type_Adapter::get_entity_types($post_type), |
|
| 26 | + function($item) { |
|
| 27 | 27 | return 'http://schema.org/Article' !== $item; |
| 28 | 28 | } ); |
| 29 | 29 | |
| 30 | - if ( empty( $entity_types ) ) { |
|
| 30 | + if (empty($entity_types)) { |
|
| 31 | 31 | return $carry; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | return $carry + array( |
| 35 | 35 | $post_type => array( |
| 36 | 36 | 'entity_types' => $entity_types, |
| 37 | - 'count' => $mapping_service->count( $post_type, $entity_types ), |
|
| 37 | + 'count' => $mapping_service->count($post_type, $entity_types), |
|
| 38 | 38 | ), |
| 39 | 39 | ); |
| 40 | 40 | }, |
| 41 | 41 | array() ); |
| 42 | 42 | |
| 43 | - $mappings['_nonce'] = wp_create_nonce( 'update_post_type_entity_types' ); |
|
| 43 | + $mappings['_nonce'] = wp_create_nonce('update_post_type_entity_types'); |
|
| 44 | 44 | |
| 45 | 45 | |
| 46 | - $json = wp_json_encode( $mappings ); |
|
| 46 | + $json = wp_json_encode($mappings); |
|
| 47 | 47 | echo "<script type='application/javascript'>var wlMappings = $json;</script>"; |
| 48 | 48 | |
| 49 | 49 | ?> |
| 50 | 50 | |
| 51 | 51 | <?php |
| 52 | 52 | |
| 53 | - foreach ( $mappings as $key => $value ) { |
|
| 53 | + foreach ($mappings as $key => $value) { |
|
| 54 | 54 | // Continue if this is the nonce. |
| 55 | - if ( '_nonce' == $key ) { |
|
| 55 | + if ('_nonce' == $key) { |
|
| 56 | 56 | continue; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | // Continue if the count isn't set or it's zero, i.e. no need to apply the taxonomy. |
| 60 | - if ( ! isset( $value['count'] ) || 0 === $value['count'] ) { |
|
| 60 | + if ( ! isset($value['count']) || 0 === $value['count']) { |
|
| 61 | 61 | continue; |
| 62 | 62 | } |
| 63 | 63 | ?> |
| 64 | 64 | <div class="post-type-to-entity-types"> |
| 65 | - <button data-post-type="<?php echo esc_attr( $key ); ?>" |
|
| 66 | - data-entity-types="<?php echo esc_attr( wp_json_encode( $value['entity_types'] ) ); ?>" |
|
| 67 | - ><?php echo esc_html( $key ); ?></button> |
|
| 68 | - <div><?php echo esc_html( $value['count'] ); ?></div> |
|
| 65 | + <button data-post-type="<?php echo esc_attr($key); ?>" |
|
| 66 | + data-entity-types="<?php echo esc_attr(wp_json_encode($value['entity_types'])); ?>" |
|
| 67 | + ><?php echo esc_html($key); ?></button> |
|
| 68 | + <div><?php echo esc_html($value['count']); ?></div> |
|
| 69 | 69 | </div> |
| 70 | 70 | <?php |
| 71 | 71 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | |
| 75 | 75 | <div id="schemaorg-sync"> |
| 76 | 76 | <button>Sync Schema.org classes</button> |
| 77 | - <div class="count"><?php echo( Wordlift_Schemaorg_Sync_Batch_Operation::get_instance()->count() ); ?></div> |
|
| 77 | + <div class="count"><?php echo(Wordlift_Schemaorg_Sync_Batch_Operation::get_instance()->count()); ?></div> |
|
| 78 | 78 | </div> |
| 79 | 79 | |
| 80 | 80 | <div class="clear"></div> |
@@ -13,238 +13,238 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class Wordlift_Entity_Post_To_Jsonld_Converter extends Wordlift_Abstract_Post_To_Jsonld_Converter { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * A {@link Wordlift_Property_Getter} instance. |
|
| 18 | - * |
|
| 19 | - * @since 3.8.0 |
|
| 20 | - * @access private |
|
| 21 | - * @var \Wordlift_Property_Getter $property_getter A {@link Wordlift_Property_Getter} instance. |
|
| 22 | - */ |
|
| 23 | - private $property_getter; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * The {@link Wordlift_Schemaorg_Property_Service} or null if not provided. |
|
| 27 | - * |
|
| 28 | - * @since 3.20.0 |
|
| 29 | - * @access private |
|
| 30 | - * @var null|Wordlift_Schemaorg_Property_Service The {@link Wordlift_Schemaorg_Property_Service} or null if not provided. |
|
| 31 | - */ |
|
| 32 | - private $schemaorg_property_service; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Wordlift_Entity_To_Jsonld_Converter constructor. |
|
| 36 | - * |
|
| 37 | - * @since 3.8.0 |
|
| 38 | - * |
|
| 39 | - * @param \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance. |
|
| 40 | - * @param \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
| 41 | - * @param \Wordlift_User_Service $user_service A {@link Wordlift_User_Service} instance. |
|
| 42 | - * @param \Wordlift_Attachment_Service $attachment_service A {@link Wordlift_Attachment_Service} instance. |
|
| 43 | - * @param \Wordlift_Property_Getter $property_getter A {@link Wordlift_Property_Getter} instance. |
|
| 44 | - * @param \Wordlift_Schemaorg_Property_Service $schemaorg_property_service A {@link Wordlift_Schemaorg_Property_Service} instance. |
|
| 45 | - */ |
|
| 46 | - public function __construct( $entity_type_service, $entity_service, $user_service, $attachment_service, $property_getter, $schemaorg_property_service = null ) { |
|
| 47 | - parent::__construct( $entity_type_service, $entity_service, $user_service, $attachment_service ); |
|
| 48 | - |
|
| 49 | - $this->property_getter = $property_getter; |
|
| 50 | - $this->schemaorg_property_service = $schemaorg_property_service; |
|
| 51 | - |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Convert the provided {@link WP_Post} to a JSON-LD array. Any entity reference |
|
| 56 | - * found while processing the post is set in the $references array. |
|
| 57 | - * |
|
| 58 | - * @since 3.8.0 |
|
| 59 | - * |
|
| 60 | - * @param int $post_id The {@link WP_Post} id. |
|
| 61 | - * |
|
| 62 | - * @param array $references An array of entity references. |
|
| 63 | - * |
|
| 64 | - * @return array A JSON-LD array. |
|
| 65 | - */ |
|
| 66 | - public function convert( $post_id, &$references = array() ) { |
|
| 67 | - |
|
| 68 | - // Get the post instance. |
|
| 69 | - $post = get_post( $post_id ); |
|
| 70 | - if ( null === $post ) { |
|
| 71 | - // Post not found. |
|
| 72 | - return null; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - // Get the base JSON-LD and the list of entities referenced by this entity. |
|
| 76 | - $jsonld = parent::convert( $post_id, $references ); |
|
| 77 | - |
|
| 78 | - // Get the entity name. |
|
| 79 | - $jsonld['name'] = $post->post_title; |
|
| 80 | - |
|
| 81 | - // 3.13.0, add alternate names. |
|
| 82 | - $alternative_labels = $this->entity_service->get_alternative_labels( $post_id ); |
|
| 83 | - if ( 0 < count( $alternative_labels ) ) { |
|
| 84 | - $jsonld['alternateName'] = $alternative_labels; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // Get the entity `@type` with custom fields set by the Wordlift_Schema_Service. |
|
| 88 | - // |
|
| 89 | - // This allows us to gather the basic properties as defined by the `Thing` entity type. |
|
| 90 | - $type = $this->entity_type_service->get( $post_id ); |
|
| 91 | - |
|
| 92 | - // Get the configured type custom fields. |
|
| 93 | - if ( isset( $type['custom_fields'] ) ) { |
|
| 94 | - $this->process_type_custom_fields( $jsonld, $type['custom_fields'], $post, $references ); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /* |
|
| 16 | + /** |
|
| 17 | + * A {@link Wordlift_Property_Getter} instance. |
|
| 18 | + * |
|
| 19 | + * @since 3.8.0 |
|
| 20 | + * @access private |
|
| 21 | + * @var \Wordlift_Property_Getter $property_getter A {@link Wordlift_Property_Getter} instance. |
|
| 22 | + */ |
|
| 23 | + private $property_getter; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * The {@link Wordlift_Schemaorg_Property_Service} or null if not provided. |
|
| 27 | + * |
|
| 28 | + * @since 3.20.0 |
|
| 29 | + * @access private |
|
| 30 | + * @var null|Wordlift_Schemaorg_Property_Service The {@link Wordlift_Schemaorg_Property_Service} or null if not provided. |
|
| 31 | + */ |
|
| 32 | + private $schemaorg_property_service; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Wordlift_Entity_To_Jsonld_Converter constructor. |
|
| 36 | + * |
|
| 37 | + * @since 3.8.0 |
|
| 38 | + * |
|
| 39 | + * @param \Wordlift_Entity_Type_Service $entity_type_service A {@link Wordlift_Entity_Type_Service} instance. |
|
| 40 | + * @param \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
| 41 | + * @param \Wordlift_User_Service $user_service A {@link Wordlift_User_Service} instance. |
|
| 42 | + * @param \Wordlift_Attachment_Service $attachment_service A {@link Wordlift_Attachment_Service} instance. |
|
| 43 | + * @param \Wordlift_Property_Getter $property_getter A {@link Wordlift_Property_Getter} instance. |
|
| 44 | + * @param \Wordlift_Schemaorg_Property_Service $schemaorg_property_service A {@link Wordlift_Schemaorg_Property_Service} instance. |
|
| 45 | + */ |
|
| 46 | + public function __construct( $entity_type_service, $entity_service, $user_service, $attachment_service, $property_getter, $schemaorg_property_service = null ) { |
|
| 47 | + parent::__construct( $entity_type_service, $entity_service, $user_service, $attachment_service ); |
|
| 48 | + |
|
| 49 | + $this->property_getter = $property_getter; |
|
| 50 | + $this->schemaorg_property_service = $schemaorg_property_service; |
|
| 51 | + |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Convert the provided {@link WP_Post} to a JSON-LD array. Any entity reference |
|
| 56 | + * found while processing the post is set in the $references array. |
|
| 57 | + * |
|
| 58 | + * @since 3.8.0 |
|
| 59 | + * |
|
| 60 | + * @param int $post_id The {@link WP_Post} id. |
|
| 61 | + * |
|
| 62 | + * @param array $references An array of entity references. |
|
| 63 | + * |
|
| 64 | + * @return array A JSON-LD array. |
|
| 65 | + */ |
|
| 66 | + public function convert( $post_id, &$references = array() ) { |
|
| 67 | + |
|
| 68 | + // Get the post instance. |
|
| 69 | + $post = get_post( $post_id ); |
|
| 70 | + if ( null === $post ) { |
|
| 71 | + // Post not found. |
|
| 72 | + return null; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + // Get the base JSON-LD and the list of entities referenced by this entity. |
|
| 76 | + $jsonld = parent::convert( $post_id, $references ); |
|
| 77 | + |
|
| 78 | + // Get the entity name. |
|
| 79 | + $jsonld['name'] = $post->post_title; |
|
| 80 | + |
|
| 81 | + // 3.13.0, add alternate names. |
|
| 82 | + $alternative_labels = $this->entity_service->get_alternative_labels( $post_id ); |
|
| 83 | + if ( 0 < count( $alternative_labels ) ) { |
|
| 84 | + $jsonld['alternateName'] = $alternative_labels; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // Get the entity `@type` with custom fields set by the Wordlift_Schema_Service. |
|
| 88 | + // |
|
| 89 | + // This allows us to gather the basic properties as defined by the `Thing` entity type. |
|
| 90 | + $type = $this->entity_type_service->get( $post_id ); |
|
| 91 | + |
|
| 92 | + // Get the configured type custom fields. |
|
| 93 | + if ( isset( $type['custom_fields'] ) ) { |
|
| 94 | + $this->process_type_custom_fields( $jsonld, $type['custom_fields'], $post, $references ); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /* |
|
| 98 | 98 | * Get the properties attached to the post. |
| 99 | 99 | * |
| 100 | 100 | * @since 3.20.0 We attach properties directly to the posts. |
| 101 | 101 | * |
| 102 | 102 | * @see https://github.com/insideout10/wordlift-plugin/issues/835 |
| 103 | 103 | */ |
| 104 | - if ( WL_ALL_ENTITY_TYPES ) { |
|
| 105 | - $this->process_post_properties( $jsonld, $post_id ); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Call the `wl_entity_jsonld` filter. |
|
| 110 | - * |
|
| 111 | - * @api |
|
| 112 | - * |
|
| 113 | - * @since 3.20.0 |
|
| 114 | - * |
|
| 115 | - * @param array $jsonld The JSON-LD structure. |
|
| 116 | - * @param int $post_id The {@link WP_Post} `id`. |
|
| 117 | - * @param array $references The array of referenced entities. |
|
| 118 | - */ |
|
| 119 | - return apply_filters( 'wl_entity_jsonld', $this->post_process( $jsonld ), $post_id, $references ); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Add data to the JSON-LD using the `custom_fields` array which contains the definitions of property |
|
| 124 | - * for the post entity type. |
|
| 125 | - * |
|
| 126 | - * @since 3.20.0 This code moved from the above function `convert`, used for entity types defined in |
|
| 127 | - * the {@link Wordlift_Schema_Service} class. |
|
| 128 | - * |
|
| 129 | - * @param array $jsonld The JSON-LD array. |
|
| 130 | - * @param array $fields The entity types field array. |
|
| 131 | - * @param WP_Post $post The target {@link WP_Post} instance. |
|
| 132 | - * @param array $references The references array. |
|
| 133 | - */ |
|
| 134 | - private function process_type_custom_fields( &$jsonld, $fields, $post, &$references ) { |
|
| 135 | - |
|
| 136 | - // Set a reference to use in closures. |
|
| 137 | - $converter = $this; |
|
| 138 | - |
|
| 139 | - // Try each field on the entity. |
|
| 140 | - foreach ( $fields as $key => $value ) { |
|
| 141 | - |
|
| 142 | - // Get the predicate. |
|
| 143 | - $name = $this->relative_to_context( $value['predicate'] ); |
|
| 144 | - |
|
| 145 | - // Get the value, the property service will get the right extractor |
|
| 146 | - // for that property. |
|
| 147 | - $value = $this->property_getter->get( $post->ID, $key ); |
|
| 148 | - |
|
| 149 | - if ( empty( $value ) ) { |
|
| 150 | - continue; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // Map the value to the property name. |
|
| 154 | - // If we got an array with just one value, we return that one value. |
|
| 155 | - // If we got a Wordlift_Property_Entity_Reference we get the URL. |
|
| 156 | - $jsonld[ $name ] = self::make_one( array_map( function ( $item ) use ( $converter, &$references ) { |
|
| 157 | - |
|
| 158 | - if ( $item instanceof Wordlift_Property_Entity_Reference ) { |
|
| 159 | - |
|
| 160 | - $url = $item->getURL(); |
|
| 161 | - |
|
| 162 | - // The refactored converters require the entity id. |
|
| 163 | - $references[] = $item->getID(); |
|
| 164 | - |
|
| 165 | - return array( |
|
| 166 | - '@id' => $url, |
|
| 167 | - ); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - return $converter->relative_to_context( $item ); |
|
| 171 | - }, $value ) ); |
|
| 172 | - |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Process the properties attached to the {@link WP_Post}. |
|
| 179 | - * |
|
| 180 | - * @since 3.20.0 |
|
| 181 | - * |
|
| 182 | - * @param array $jsonld The JSON-LD array. |
|
| 183 | - * @param int $post_id The target {@link WP_Post} id. |
|
| 184 | - */ |
|
| 185 | - private function process_post_properties( &$jsonld, $post_id ) { |
|
| 186 | - |
|
| 187 | - // Get all the props. |
|
| 188 | - $props = $this->schemaorg_property_service->get_all( $post_id ); |
|
| 189 | - |
|
| 190 | - // Process all the props. |
|
| 191 | - foreach ( $props as $name => $instances ) { |
|
| 192 | - |
|
| 193 | - // Get the values. |
|
| 194 | - $values = array_map( function ( $instance ) { |
|
| 195 | - return $instance['value']; |
|
| 196 | - }, $instances ); |
|
| 197 | - |
|
| 198 | - // We might receive empty values, remove them. |
|
| 199 | - $non_empty_values = array_filter( $values, function ( $value ) { |
|
| 200 | - return ! empty( $value ); |
|
| 201 | - } ); |
|
| 202 | - |
|
| 203 | - // Skip empty properties. |
|
| 204 | - if ( empty( $non_empty_values ) ) { |
|
| 205 | - continue; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - // @@todo: need to handle maybe Numbers and URLs differently. |
|
| 209 | - // Make an array a single value when possible. |
|
| 210 | - $jsonld[ $name ] = self::make_one( $non_empty_values ); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Post process the generated JSON to reorganize values which are stored as 1st |
|
| 217 | - * level in WP but are really 2nd level. |
|
| 218 | - * |
|
| 219 | - * @since 3.8.0 |
|
| 220 | - * |
|
| 221 | - * @param array $jsonld An array of JSON-LD properties and values. |
|
| 222 | - * |
|
| 223 | - * @return array The array remapped. |
|
| 224 | - */ |
|
| 225 | - private function post_process( $jsonld ) { |
|
| 226 | - |
|
| 227 | - foreach ( $jsonld as $key => $value ) { |
|
| 228 | - if ( 'streetAddress' === $key || 'postalCode' === $key || 'addressLocality' === $key || 'addressRegion' === $key || 'addressCountry' === $key || 'postOfficeBoxNumber' === $key ) { |
|
| 229 | - $jsonld['address']['@type'] = 'PostalAddress'; |
|
| 230 | - $jsonld['address'][ $key ] = $value; |
|
| 231 | - unset( $jsonld[ $key ] ); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - if ( 'latitude' === $key || 'longitude' === $key ) { |
|
| 235 | - $jsonld['geo']['@type'] = 'GeoCoordinates'; |
|
| 236 | - $jsonld['geo'][ $key ] = $value; |
|
| 237 | - unset( $jsonld[ $key ] ); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - if ( 'calories' === $key ) { |
|
| 241 | - $jsonld['nutrition']['@type'] = 'NutritionInformation'; |
|
| 242 | - $jsonld['nutrition'][ $key ] = $value; |
|
| 243 | - unset( $jsonld[ $key ] ); |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - return $jsonld; |
|
| 248 | - } |
|
| 104 | + if ( WL_ALL_ENTITY_TYPES ) { |
|
| 105 | + $this->process_post_properties( $jsonld, $post_id ); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Call the `wl_entity_jsonld` filter. |
|
| 110 | + * |
|
| 111 | + * @api |
|
| 112 | + * |
|
| 113 | + * @since 3.20.0 |
|
| 114 | + * |
|
| 115 | + * @param array $jsonld The JSON-LD structure. |
|
| 116 | + * @param int $post_id The {@link WP_Post} `id`. |
|
| 117 | + * @param array $references The array of referenced entities. |
|
| 118 | + */ |
|
| 119 | + return apply_filters( 'wl_entity_jsonld', $this->post_process( $jsonld ), $post_id, $references ); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Add data to the JSON-LD using the `custom_fields` array which contains the definitions of property |
|
| 124 | + * for the post entity type. |
|
| 125 | + * |
|
| 126 | + * @since 3.20.0 This code moved from the above function `convert`, used for entity types defined in |
|
| 127 | + * the {@link Wordlift_Schema_Service} class. |
|
| 128 | + * |
|
| 129 | + * @param array $jsonld The JSON-LD array. |
|
| 130 | + * @param array $fields The entity types field array. |
|
| 131 | + * @param WP_Post $post The target {@link WP_Post} instance. |
|
| 132 | + * @param array $references The references array. |
|
| 133 | + */ |
|
| 134 | + private function process_type_custom_fields( &$jsonld, $fields, $post, &$references ) { |
|
| 135 | + |
|
| 136 | + // Set a reference to use in closures. |
|
| 137 | + $converter = $this; |
|
| 138 | + |
|
| 139 | + // Try each field on the entity. |
|
| 140 | + foreach ( $fields as $key => $value ) { |
|
| 141 | + |
|
| 142 | + // Get the predicate. |
|
| 143 | + $name = $this->relative_to_context( $value['predicate'] ); |
|
| 144 | + |
|
| 145 | + // Get the value, the property service will get the right extractor |
|
| 146 | + // for that property. |
|
| 147 | + $value = $this->property_getter->get( $post->ID, $key ); |
|
| 148 | + |
|
| 149 | + if ( empty( $value ) ) { |
|
| 150 | + continue; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // Map the value to the property name. |
|
| 154 | + // If we got an array with just one value, we return that one value. |
|
| 155 | + // If we got a Wordlift_Property_Entity_Reference we get the URL. |
|
| 156 | + $jsonld[ $name ] = self::make_one( array_map( function ( $item ) use ( $converter, &$references ) { |
|
| 157 | + |
|
| 158 | + if ( $item instanceof Wordlift_Property_Entity_Reference ) { |
|
| 159 | + |
|
| 160 | + $url = $item->getURL(); |
|
| 161 | + |
|
| 162 | + // The refactored converters require the entity id. |
|
| 163 | + $references[] = $item->getID(); |
|
| 164 | + |
|
| 165 | + return array( |
|
| 166 | + '@id' => $url, |
|
| 167 | + ); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + return $converter->relative_to_context( $item ); |
|
| 171 | + }, $value ) ); |
|
| 172 | + |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Process the properties attached to the {@link WP_Post}. |
|
| 179 | + * |
|
| 180 | + * @since 3.20.0 |
|
| 181 | + * |
|
| 182 | + * @param array $jsonld The JSON-LD array. |
|
| 183 | + * @param int $post_id The target {@link WP_Post} id. |
|
| 184 | + */ |
|
| 185 | + private function process_post_properties( &$jsonld, $post_id ) { |
|
| 186 | + |
|
| 187 | + // Get all the props. |
|
| 188 | + $props = $this->schemaorg_property_service->get_all( $post_id ); |
|
| 189 | + |
|
| 190 | + // Process all the props. |
|
| 191 | + foreach ( $props as $name => $instances ) { |
|
| 192 | + |
|
| 193 | + // Get the values. |
|
| 194 | + $values = array_map( function ( $instance ) { |
|
| 195 | + return $instance['value']; |
|
| 196 | + }, $instances ); |
|
| 197 | + |
|
| 198 | + // We might receive empty values, remove them. |
|
| 199 | + $non_empty_values = array_filter( $values, function ( $value ) { |
|
| 200 | + return ! empty( $value ); |
|
| 201 | + } ); |
|
| 202 | + |
|
| 203 | + // Skip empty properties. |
|
| 204 | + if ( empty( $non_empty_values ) ) { |
|
| 205 | + continue; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + // @@todo: need to handle maybe Numbers and URLs differently. |
|
| 209 | + // Make an array a single value when possible. |
|
| 210 | + $jsonld[ $name ] = self::make_one( $non_empty_values ); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Post process the generated JSON to reorganize values which are stored as 1st |
|
| 217 | + * level in WP but are really 2nd level. |
|
| 218 | + * |
|
| 219 | + * @since 3.8.0 |
|
| 220 | + * |
|
| 221 | + * @param array $jsonld An array of JSON-LD properties and values. |
|
| 222 | + * |
|
| 223 | + * @return array The array remapped. |
|
| 224 | + */ |
|
| 225 | + private function post_process( $jsonld ) { |
|
| 226 | + |
|
| 227 | + foreach ( $jsonld as $key => $value ) { |
|
| 228 | + if ( 'streetAddress' === $key || 'postalCode' === $key || 'addressLocality' === $key || 'addressRegion' === $key || 'addressCountry' === $key || 'postOfficeBoxNumber' === $key ) { |
|
| 229 | + $jsonld['address']['@type'] = 'PostalAddress'; |
|
| 230 | + $jsonld['address'][ $key ] = $value; |
|
| 231 | + unset( $jsonld[ $key ] ); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + if ( 'latitude' === $key || 'longitude' === $key ) { |
|
| 235 | + $jsonld['geo']['@type'] = 'GeoCoordinates'; |
|
| 236 | + $jsonld['geo'][ $key ] = $value; |
|
| 237 | + unset( $jsonld[ $key ] ); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + if ( 'calories' === $key ) { |
|
| 241 | + $jsonld['nutrition']['@type'] = 'NutritionInformation'; |
|
| 242 | + $jsonld['nutrition'][ $key ] = $value; |
|
| 243 | + unset( $jsonld[ $key ] ); |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + return $jsonld; |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | 250 | } |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | * @param \Wordlift_Property_Getter $property_getter A {@link Wordlift_Property_Getter} instance. |
| 44 | 44 | * @param \Wordlift_Schemaorg_Property_Service $schemaorg_property_service A {@link Wordlift_Schemaorg_Property_Service} instance. |
| 45 | 45 | */ |
| 46 | - public function __construct( $entity_type_service, $entity_service, $user_service, $attachment_service, $property_getter, $schemaorg_property_service = null ) { |
|
| 47 | - parent::__construct( $entity_type_service, $entity_service, $user_service, $attachment_service ); |
|
| 46 | + public function __construct($entity_type_service, $entity_service, $user_service, $attachment_service, $property_getter, $schemaorg_property_service = null) { |
|
| 47 | + parent::__construct($entity_type_service, $entity_service, $user_service, $attachment_service); |
|
| 48 | 48 | |
| 49 | 49 | $this->property_getter = $property_getter; |
| 50 | 50 | $this->schemaorg_property_service = $schemaorg_property_service; |
@@ -63,35 +63,35 @@ discard block |
||
| 63 | 63 | * |
| 64 | 64 | * @return array A JSON-LD array. |
| 65 | 65 | */ |
| 66 | - public function convert( $post_id, &$references = array() ) { |
|
| 66 | + public function convert($post_id, &$references = array()) { |
|
| 67 | 67 | |
| 68 | 68 | // Get the post instance. |
| 69 | - $post = get_post( $post_id ); |
|
| 70 | - if ( null === $post ) { |
|
| 69 | + $post = get_post($post_id); |
|
| 70 | + if (null === $post) { |
|
| 71 | 71 | // Post not found. |
| 72 | 72 | return null; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | // Get the base JSON-LD and the list of entities referenced by this entity. |
| 76 | - $jsonld = parent::convert( $post_id, $references ); |
|
| 76 | + $jsonld = parent::convert($post_id, $references); |
|
| 77 | 77 | |
| 78 | 78 | // Get the entity name. |
| 79 | 79 | $jsonld['name'] = $post->post_title; |
| 80 | 80 | |
| 81 | 81 | // 3.13.0, add alternate names. |
| 82 | - $alternative_labels = $this->entity_service->get_alternative_labels( $post_id ); |
|
| 83 | - if ( 0 < count( $alternative_labels ) ) { |
|
| 82 | + $alternative_labels = $this->entity_service->get_alternative_labels($post_id); |
|
| 83 | + if (0 < count($alternative_labels)) { |
|
| 84 | 84 | $jsonld['alternateName'] = $alternative_labels; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | // Get the entity `@type` with custom fields set by the Wordlift_Schema_Service. |
| 88 | 88 | // |
| 89 | 89 | // This allows us to gather the basic properties as defined by the `Thing` entity type. |
| 90 | - $type = $this->entity_type_service->get( $post_id ); |
|
| 90 | + $type = $this->entity_type_service->get($post_id); |
|
| 91 | 91 | |
| 92 | 92 | // Get the configured type custom fields. |
| 93 | - if ( isset( $type['custom_fields'] ) ) { |
|
| 94 | - $this->process_type_custom_fields( $jsonld, $type['custom_fields'], $post, $references ); |
|
| 93 | + if (isset($type['custom_fields'])) { |
|
| 94 | + $this->process_type_custom_fields($jsonld, $type['custom_fields'], $post, $references); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /* |
@@ -101,8 +101,8 @@ discard block |
||
| 101 | 101 | * |
| 102 | 102 | * @see https://github.com/insideout10/wordlift-plugin/issues/835 |
| 103 | 103 | */ |
| 104 | - if ( WL_ALL_ENTITY_TYPES ) { |
|
| 105 | - $this->process_post_properties( $jsonld, $post_id ); |
|
| 104 | + if (WL_ALL_ENTITY_TYPES) { |
|
| 105 | + $this->process_post_properties($jsonld, $post_id); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | * @param int $post_id The {@link WP_Post} `id`. |
| 117 | 117 | * @param array $references The array of referenced entities. |
| 118 | 118 | */ |
| 119 | - return apply_filters( 'wl_entity_jsonld', $this->post_process( $jsonld ), $post_id, $references ); |
|
| 119 | + return apply_filters('wl_entity_jsonld', $this->post_process($jsonld), $post_id, $references); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -131,31 +131,31 @@ discard block |
||
| 131 | 131 | * @param WP_Post $post The target {@link WP_Post} instance. |
| 132 | 132 | * @param array $references The references array. |
| 133 | 133 | */ |
| 134 | - private function process_type_custom_fields( &$jsonld, $fields, $post, &$references ) { |
|
| 134 | + private function process_type_custom_fields(&$jsonld, $fields, $post, &$references) { |
|
| 135 | 135 | |
| 136 | 136 | // Set a reference to use in closures. |
| 137 | 137 | $converter = $this; |
| 138 | 138 | |
| 139 | 139 | // Try each field on the entity. |
| 140 | - foreach ( $fields as $key => $value ) { |
|
| 140 | + foreach ($fields as $key => $value) { |
|
| 141 | 141 | |
| 142 | 142 | // Get the predicate. |
| 143 | - $name = $this->relative_to_context( $value['predicate'] ); |
|
| 143 | + $name = $this->relative_to_context($value['predicate']); |
|
| 144 | 144 | |
| 145 | 145 | // Get the value, the property service will get the right extractor |
| 146 | 146 | // for that property. |
| 147 | - $value = $this->property_getter->get( $post->ID, $key ); |
|
| 147 | + $value = $this->property_getter->get($post->ID, $key); |
|
| 148 | 148 | |
| 149 | - if ( empty( $value ) ) { |
|
| 149 | + if (empty($value)) { |
|
| 150 | 150 | continue; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | // Map the value to the property name. |
| 154 | 154 | // If we got an array with just one value, we return that one value. |
| 155 | 155 | // If we got a Wordlift_Property_Entity_Reference we get the URL. |
| 156 | - $jsonld[ $name ] = self::make_one( array_map( function ( $item ) use ( $converter, &$references ) { |
|
| 156 | + $jsonld[$name] = self::make_one(array_map(function($item) use ($converter, &$references) { |
|
| 157 | 157 | |
| 158 | - if ( $item instanceof Wordlift_Property_Entity_Reference ) { |
|
| 158 | + if ($item instanceof Wordlift_Property_Entity_Reference) { |
|
| 159 | 159 | |
| 160 | 160 | $url = $item->getURL(); |
| 161 | 161 | |
@@ -167,8 +167,8 @@ discard block |
||
| 167 | 167 | ); |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - return $converter->relative_to_context( $item ); |
|
| 171 | - }, $value ) ); |
|
| 170 | + return $converter->relative_to_context($item); |
|
| 171 | + }, $value)); |
|
| 172 | 172 | |
| 173 | 173 | } |
| 174 | 174 | |
@@ -182,32 +182,32 @@ discard block |
||
| 182 | 182 | * @param array $jsonld The JSON-LD array. |
| 183 | 183 | * @param int $post_id The target {@link WP_Post} id. |
| 184 | 184 | */ |
| 185 | - private function process_post_properties( &$jsonld, $post_id ) { |
|
| 185 | + private function process_post_properties(&$jsonld, $post_id) { |
|
| 186 | 186 | |
| 187 | 187 | // Get all the props. |
| 188 | - $props = $this->schemaorg_property_service->get_all( $post_id ); |
|
| 188 | + $props = $this->schemaorg_property_service->get_all($post_id); |
|
| 189 | 189 | |
| 190 | 190 | // Process all the props. |
| 191 | - foreach ( $props as $name => $instances ) { |
|
| 191 | + foreach ($props as $name => $instances) { |
|
| 192 | 192 | |
| 193 | 193 | // Get the values. |
| 194 | - $values = array_map( function ( $instance ) { |
|
| 194 | + $values = array_map(function($instance) { |
|
| 195 | 195 | return $instance['value']; |
| 196 | - }, $instances ); |
|
| 196 | + }, $instances); |
|
| 197 | 197 | |
| 198 | 198 | // We might receive empty values, remove them. |
| 199 | - $non_empty_values = array_filter( $values, function ( $value ) { |
|
| 200 | - return ! empty( $value ); |
|
| 199 | + $non_empty_values = array_filter($values, function($value) { |
|
| 200 | + return ! empty($value); |
|
| 201 | 201 | } ); |
| 202 | 202 | |
| 203 | 203 | // Skip empty properties. |
| 204 | - if ( empty( $non_empty_values ) ) { |
|
| 204 | + if (empty($non_empty_values)) { |
|
| 205 | 205 | continue; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | // @@todo: need to handle maybe Numbers and URLs differently. |
| 209 | 209 | // Make an array a single value when possible. |
| 210 | - $jsonld[ $name ] = self::make_one( $non_empty_values ); |
|
| 210 | + $jsonld[$name] = self::make_one($non_empty_values); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | } |
@@ -222,25 +222,25 @@ discard block |
||
| 222 | 222 | * |
| 223 | 223 | * @return array The array remapped. |
| 224 | 224 | */ |
| 225 | - private function post_process( $jsonld ) { |
|
| 225 | + private function post_process($jsonld) { |
|
| 226 | 226 | |
| 227 | - foreach ( $jsonld as $key => $value ) { |
|
| 228 | - if ( 'streetAddress' === $key || 'postalCode' === $key || 'addressLocality' === $key || 'addressRegion' === $key || 'addressCountry' === $key || 'postOfficeBoxNumber' === $key ) { |
|
| 227 | + foreach ($jsonld as $key => $value) { |
|
| 228 | + if ('streetAddress' === $key || 'postalCode' === $key || 'addressLocality' === $key || 'addressRegion' === $key || 'addressCountry' === $key || 'postOfficeBoxNumber' === $key) { |
|
| 229 | 229 | $jsonld['address']['@type'] = 'PostalAddress'; |
| 230 | - $jsonld['address'][ $key ] = $value; |
|
| 231 | - unset( $jsonld[ $key ] ); |
|
| 230 | + $jsonld['address'][$key] = $value; |
|
| 231 | + unset($jsonld[$key]); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | - if ( 'latitude' === $key || 'longitude' === $key ) { |
|
| 234 | + if ('latitude' === $key || 'longitude' === $key) { |
|
| 235 | 235 | $jsonld['geo']['@type'] = 'GeoCoordinates'; |
| 236 | - $jsonld['geo'][ $key ] = $value; |
|
| 237 | - unset( $jsonld[ $key ] ); |
|
| 236 | + $jsonld['geo'][$key] = $value; |
|
| 237 | + unset($jsonld[$key]); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - if ( 'calories' === $key ) { |
|
| 240 | + if ('calories' === $key) { |
|
| 241 | 241 | $jsonld['nutrition']['@type'] = 'NutritionInformation'; |
| 242 | - $jsonld['nutrition'][ $key ] = $value; |
|
| 243 | - unset( $jsonld[ $key ] ); |
|
| 242 | + $jsonld['nutrition'][$key] = $value; |
|
| 243 | + unset($jsonld[$key]); |
|
| 244 | 244 | } |
| 245 | 245 | } |
| 246 | 246 | |