@@ -177,7 +177,7 @@ |
||
| 177 | 177 | * @since 3.6.0 |
| 178 | 178 | * |
| 179 | 179 | * @param string $slug The slug. |
| 180 | - * @param array $post_types An array of post types. |
|
| 180 | + * @param string[] $post_types An array of post types. |
|
| 181 | 181 | * |
| 182 | 182 | * @return bool True if the slug exists, otherwise false. |
| 183 | 183 | */ |
@@ -24,170 +24,170 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class Wordlift_Entity_Link_Service { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * The entity type service. |
|
| 29 | - * |
|
| 30 | - * @since 3.6.0 |
|
| 31 | - * @access private |
|
| 32 | - * @var Wordlift_Entity_Type_Service $entity_type_service The entity type service. |
|
| 33 | - */ |
|
| 34 | - private $entity_type_service; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * The entity post type slug. |
|
| 38 | - * |
|
| 39 | - * @since 3.6.0 |
|
| 40 | - * @access private |
|
| 41 | - * @var string $slug The entity post type slug. |
|
| 42 | - */ |
|
| 43 | - private $slug; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * A logger instance. |
|
| 47 | - * |
|
| 48 | - * @since 3.6.0 |
|
| 49 | - * @access private |
|
| 50 | - * @var Wordlift_Log_Service |
|
| 51 | - */ |
|
| 52 | - private $log; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Wordlift_Entity_Link_Service constructor. |
|
| 56 | - * |
|
| 57 | - * @since 3.6.0 |
|
| 58 | - * |
|
| 59 | - * @param Wordlift_Entity_Type_Service $entity_type_service |
|
| 60 | - * @param string $slug The entity post type slug. |
|
| 61 | - */ |
|
| 62 | - public function __construct( $entity_type_service, $slug ) { |
|
| 63 | - |
|
| 64 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Link_Service' ); |
|
| 65 | - |
|
| 66 | - $this->entity_type_service = $entity_type_service; |
|
| 67 | - $this->slug = $slug; |
|
| 68 | - |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Intercept link generation to posts in order to customize links to entities. |
|
| 73 | - * |
|
| 74 | - * @since 3.6.0 |
|
| 75 | - * |
|
| 76 | - * @param string $post_link The post's permalink. |
|
| 77 | - * @param WP_Post $post The post in question. |
|
| 78 | - * @param bool $leavename Whether to keep the post name. |
|
| 79 | - * @param bool $sample Is it a sample permalink. |
|
| 80 | - * |
|
| 81 | - * @return string The link to the post. |
|
| 82 | - */ |
|
| 83 | - public function post_type_link( $post_link, $post, $leavename, $sample ) { |
|
| 84 | - |
|
| 85 | - // Return the post link if this is not our post type. |
|
| 86 | - if ( ! empty( $this->slug ) || $this->entity_type_service->get_post_type() !== get_post_type( $post ) ) { |
|
| 87 | - return $post_link; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - // Replace /slug/post_name/ with /post_name/ |
|
| 91 | - // The slug comes from the Entity Type Service since that service is responsible for registering the default |
|
| 92 | - // slug. |
|
| 93 | - return str_replace( "/{$this->entity_type_service->get_slug()}/$post->post_name/", "/$post->post_name/", $post_link ); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Alter the query to look for our own custom type. |
|
| 98 | - * |
|
| 99 | - * @since 3.6.0 |
|
| 100 | - * |
|
| 101 | - * @param WP_Query $query |
|
| 102 | - */ |
|
| 103 | - public function pre_get_posts( $query ) { |
|
| 104 | - |
|
| 105 | - // If a slug has been set, we don't need to alter the query. |
|
| 106 | - if ( ! empty( $this->slug ) ) { |
|
| 107 | - return; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - // Check if it's a query we should extend with our own custom post type. |
|
| 111 | - if ( ! $query->is_main_query() || 2 != count( $query->query ) || ! isset( $query->query['page'] ) || empty( $query->query['name'] ) ) { |
|
| 112 | - return; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - // Add our own post type to the query. |
|
| 116 | - $post_type = is_array( $query->get( 'post_type' ) ) ? $query->get( 'post_type' ) : array(); |
|
| 117 | - $query->set( 'post_type', array_merge( $post_type, array( 'post', $this->entity_type_service->get_post_type(), 'page' ) ) ); |
|
| 118 | - |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Hook to WordPress' wp_unique_post_slug_is_bad_flat_slug filter. This is called when a page is saved. |
|
| 123 | - * |
|
| 124 | - * @since 3.6.0 |
|
| 125 | - * |
|
| 126 | - * @param bool $bad_slug Whether the post slug would be bad as a flat slug. |
|
| 127 | - * @param string $slug The post slug. |
|
| 128 | - * @param string $post_type Post type. |
|
| 129 | - * |
|
| 130 | - * @return bool Whether the slug is bad. |
|
| 131 | - */ |
|
| 132 | - public function wp_unique_post_slug_is_bad_flat_slug( $bad_slug, $slug, $post_type ) { |
|
| 133 | - |
|
| 134 | - // The list of post types that might have conflicting slugs. |
|
| 135 | - $post_types = array( 'post', 'page', $this->entity_type_service->get_post_type() ); |
|
| 136 | - |
|
| 137 | - // Ignore post types different from the ones we need to check. |
|
| 138 | - if ( ! in_array( $post_type, $post_types ) ) { |
|
| 139 | - return $bad_slug; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - $exists = $this->slug_exists( $slug, array_diff( $post_types, array( $post_type ) ) ); |
|
| 143 | - |
|
| 144 | - $this->log->debug( "[ exists :: " . ( $exists ? "yes" : "no" ) . " ]" ); |
|
| 145 | - |
|
| 146 | - return $exists; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Hook to WordPress' wp_unique_post_slug_is_bad_hierarchical_slug filter. This is called when a page is saved. |
|
| 151 | - * |
|
| 152 | - * @since 3.6.0 |
|
| 153 | - * |
|
| 154 | - * @param bool $bad_slug Whether the post slug would be bad as a flat slug. |
|
| 155 | - * @param string $slug The post slug. |
|
| 156 | - * @param string $post_type Post type. |
|
| 157 | - * @param int $post_parent |
|
| 158 | - * |
|
| 159 | - * @return bool Whether the slug is bad. |
|
| 160 | - */ |
|
| 161 | - public function wp_unique_post_slug_is_bad_hierarchical_slug( $bad_slug, $slug, $post_type, $post_parent ) { |
|
| 162 | - |
|
| 163 | - // We only care about pages here. |
|
| 164 | - if ( 'page' !== $post_type ) { |
|
| 165 | - return $bad_slug; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - // We redirect the call to the flat hook, this means that this check is going to solve also the 6-years old issue |
|
| 169 | - // about overlapping slugs among pages and posts: |
|
| 170 | - // https://core.trac.wordpress.org/ticket/13459 |
|
| 171 | - return $this->wp_unique_post_slug_is_bad_flat_slug( $bad_slug, $slug, $post_type ); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Check whether a slug exists already for the specified post types. |
|
| 176 | - * |
|
| 177 | - * @since 3.6.0 |
|
| 178 | - * |
|
| 179 | - * @param string $slug The slug. |
|
| 180 | - * @param array $post_types An array of post types. |
|
| 181 | - * |
|
| 182 | - * @return bool True if the slug exists, otherwise false. |
|
| 183 | - */ |
|
| 184 | - private function slug_exists( $slug, $post_types ) { |
|
| 185 | - global $wpdb; |
|
| 186 | - |
|
| 187 | - // Post slugs must be unique across all posts. |
|
| 188 | - $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ('" . implode( "', '", array_map( 'esc_sql', $post_types ) ) . "') LIMIT 1"; |
|
| 189 | - |
|
| 190 | - return null !== $wpdb->get_var( $wpdb->prepare( $check_sql, $slug ) ); |
|
| 191 | - } |
|
| 27 | + /** |
|
| 28 | + * The entity type service. |
|
| 29 | + * |
|
| 30 | + * @since 3.6.0 |
|
| 31 | + * @access private |
|
| 32 | + * @var Wordlift_Entity_Type_Service $entity_type_service The entity type service. |
|
| 33 | + */ |
|
| 34 | + private $entity_type_service; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * The entity post type slug. |
|
| 38 | + * |
|
| 39 | + * @since 3.6.0 |
|
| 40 | + * @access private |
|
| 41 | + * @var string $slug The entity post type slug. |
|
| 42 | + */ |
|
| 43 | + private $slug; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * A logger instance. |
|
| 47 | + * |
|
| 48 | + * @since 3.6.0 |
|
| 49 | + * @access private |
|
| 50 | + * @var Wordlift_Log_Service |
|
| 51 | + */ |
|
| 52 | + private $log; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Wordlift_Entity_Link_Service constructor. |
|
| 56 | + * |
|
| 57 | + * @since 3.6.0 |
|
| 58 | + * |
|
| 59 | + * @param Wordlift_Entity_Type_Service $entity_type_service |
|
| 60 | + * @param string $slug The entity post type slug. |
|
| 61 | + */ |
|
| 62 | + public function __construct( $entity_type_service, $slug ) { |
|
| 63 | + |
|
| 64 | + $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Link_Service' ); |
|
| 65 | + |
|
| 66 | + $this->entity_type_service = $entity_type_service; |
|
| 67 | + $this->slug = $slug; |
|
| 68 | + |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Intercept link generation to posts in order to customize links to entities. |
|
| 73 | + * |
|
| 74 | + * @since 3.6.0 |
|
| 75 | + * |
|
| 76 | + * @param string $post_link The post's permalink. |
|
| 77 | + * @param WP_Post $post The post in question. |
|
| 78 | + * @param bool $leavename Whether to keep the post name. |
|
| 79 | + * @param bool $sample Is it a sample permalink. |
|
| 80 | + * |
|
| 81 | + * @return string The link to the post. |
|
| 82 | + */ |
|
| 83 | + public function post_type_link( $post_link, $post, $leavename, $sample ) { |
|
| 84 | + |
|
| 85 | + // Return the post link if this is not our post type. |
|
| 86 | + if ( ! empty( $this->slug ) || $this->entity_type_service->get_post_type() !== get_post_type( $post ) ) { |
|
| 87 | + return $post_link; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + // Replace /slug/post_name/ with /post_name/ |
|
| 91 | + // The slug comes from the Entity Type Service since that service is responsible for registering the default |
|
| 92 | + // slug. |
|
| 93 | + return str_replace( "/{$this->entity_type_service->get_slug()}/$post->post_name/", "/$post->post_name/", $post_link ); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Alter the query to look for our own custom type. |
|
| 98 | + * |
|
| 99 | + * @since 3.6.0 |
|
| 100 | + * |
|
| 101 | + * @param WP_Query $query |
|
| 102 | + */ |
|
| 103 | + public function pre_get_posts( $query ) { |
|
| 104 | + |
|
| 105 | + // If a slug has been set, we don't need to alter the query. |
|
| 106 | + if ( ! empty( $this->slug ) ) { |
|
| 107 | + return; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + // Check if it's a query we should extend with our own custom post type. |
|
| 111 | + if ( ! $query->is_main_query() || 2 != count( $query->query ) || ! isset( $query->query['page'] ) || empty( $query->query['name'] ) ) { |
|
| 112 | + return; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + // Add our own post type to the query. |
|
| 116 | + $post_type = is_array( $query->get( 'post_type' ) ) ? $query->get( 'post_type' ) : array(); |
|
| 117 | + $query->set( 'post_type', array_merge( $post_type, array( 'post', $this->entity_type_service->get_post_type(), 'page' ) ) ); |
|
| 118 | + |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Hook to WordPress' wp_unique_post_slug_is_bad_flat_slug filter. This is called when a page is saved. |
|
| 123 | + * |
|
| 124 | + * @since 3.6.0 |
|
| 125 | + * |
|
| 126 | + * @param bool $bad_slug Whether the post slug would be bad as a flat slug. |
|
| 127 | + * @param string $slug The post slug. |
|
| 128 | + * @param string $post_type Post type. |
|
| 129 | + * |
|
| 130 | + * @return bool Whether the slug is bad. |
|
| 131 | + */ |
|
| 132 | + public function wp_unique_post_slug_is_bad_flat_slug( $bad_slug, $slug, $post_type ) { |
|
| 133 | + |
|
| 134 | + // The list of post types that might have conflicting slugs. |
|
| 135 | + $post_types = array( 'post', 'page', $this->entity_type_service->get_post_type() ); |
|
| 136 | + |
|
| 137 | + // Ignore post types different from the ones we need to check. |
|
| 138 | + if ( ! in_array( $post_type, $post_types ) ) { |
|
| 139 | + return $bad_slug; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + $exists = $this->slug_exists( $slug, array_diff( $post_types, array( $post_type ) ) ); |
|
| 143 | + |
|
| 144 | + $this->log->debug( "[ exists :: " . ( $exists ? "yes" : "no" ) . " ]" ); |
|
| 145 | + |
|
| 146 | + return $exists; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Hook to WordPress' wp_unique_post_slug_is_bad_hierarchical_slug filter. This is called when a page is saved. |
|
| 151 | + * |
|
| 152 | + * @since 3.6.0 |
|
| 153 | + * |
|
| 154 | + * @param bool $bad_slug Whether the post slug would be bad as a flat slug. |
|
| 155 | + * @param string $slug The post slug. |
|
| 156 | + * @param string $post_type Post type. |
|
| 157 | + * @param int $post_parent |
|
| 158 | + * |
|
| 159 | + * @return bool Whether the slug is bad. |
|
| 160 | + */ |
|
| 161 | + public function wp_unique_post_slug_is_bad_hierarchical_slug( $bad_slug, $slug, $post_type, $post_parent ) { |
|
| 162 | + |
|
| 163 | + // We only care about pages here. |
|
| 164 | + if ( 'page' !== $post_type ) { |
|
| 165 | + return $bad_slug; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + // We redirect the call to the flat hook, this means that this check is going to solve also the 6-years old issue |
|
| 169 | + // about overlapping slugs among pages and posts: |
|
| 170 | + // https://core.trac.wordpress.org/ticket/13459 |
|
| 171 | + return $this->wp_unique_post_slug_is_bad_flat_slug( $bad_slug, $slug, $post_type ); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Check whether a slug exists already for the specified post types. |
|
| 176 | + * |
|
| 177 | + * @since 3.6.0 |
|
| 178 | + * |
|
| 179 | + * @param string $slug The slug. |
|
| 180 | + * @param array $post_types An array of post types. |
|
| 181 | + * |
|
| 182 | + * @return bool True if the slug exists, otherwise false. |
|
| 183 | + */ |
|
| 184 | + private function slug_exists( $slug, $post_types ) { |
|
| 185 | + global $wpdb; |
|
| 186 | + |
|
| 187 | + // Post slugs must be unique across all posts. |
|
| 188 | + $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ('" . implode( "', '", array_map( 'esc_sql', $post_types ) ) . "') LIMIT 1"; |
|
| 189 | + |
|
| 190 | + return null !== $wpdb->get_var( $wpdb->prepare( $check_sql, $slug ) ); |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | 193 | } |
@@ -59,9 +59,9 @@ discard block |
||
| 59 | 59 | * @param Wordlift_Entity_Type_Service $entity_type_service |
| 60 | 60 | * @param string $slug The entity post type slug. |
| 61 | 61 | */ |
| 62 | - public function __construct( $entity_type_service, $slug ) { |
|
| 62 | + public function __construct($entity_type_service, $slug) { |
|
| 63 | 63 | |
| 64 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Link_Service' ); |
|
| 64 | + $this->log = Wordlift_Log_Service::get_logger('Wordlift_Entity_Link_Service'); |
|
| 65 | 65 | |
| 66 | 66 | $this->entity_type_service = $entity_type_service; |
| 67 | 67 | $this->slug = $slug; |
@@ -80,17 +80,17 @@ discard block |
||
| 80 | 80 | * |
| 81 | 81 | * @return string The link to the post. |
| 82 | 82 | */ |
| 83 | - public function post_type_link( $post_link, $post, $leavename, $sample ) { |
|
| 83 | + public function post_type_link($post_link, $post, $leavename, $sample) { |
|
| 84 | 84 | |
| 85 | 85 | // Return the post link if this is not our post type. |
| 86 | - if ( ! empty( $this->slug ) || $this->entity_type_service->get_post_type() !== get_post_type( $post ) ) { |
|
| 86 | + if ( ! empty($this->slug) || $this->entity_type_service->get_post_type() !== get_post_type($post)) { |
|
| 87 | 87 | return $post_link; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | // Replace /slug/post_name/ with /post_name/ |
| 91 | 91 | // The slug comes from the Entity Type Service since that service is responsible for registering the default |
| 92 | 92 | // slug. |
| 93 | - return str_replace( "/{$this->entity_type_service->get_slug()}/$post->post_name/", "/$post->post_name/", $post_link ); |
|
| 93 | + return str_replace("/{$this->entity_type_service->get_slug()}/$post->post_name/", "/$post->post_name/", $post_link); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -100,21 +100,21 @@ discard block |
||
| 100 | 100 | * |
| 101 | 101 | * @param WP_Query $query |
| 102 | 102 | */ |
| 103 | - public function pre_get_posts( $query ) { |
|
| 103 | + public function pre_get_posts($query) { |
|
| 104 | 104 | |
| 105 | 105 | // If a slug has been set, we don't need to alter the query. |
| 106 | - if ( ! empty( $this->slug ) ) { |
|
| 106 | + if ( ! empty($this->slug)) { |
|
| 107 | 107 | return; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | // Check if it's a query we should extend with our own custom post type. |
| 111 | - if ( ! $query->is_main_query() || 2 != count( $query->query ) || ! isset( $query->query['page'] ) || empty( $query->query['name'] ) ) { |
|
| 111 | + if ( ! $query->is_main_query() || 2 != count($query->query) || ! isset($query->query['page']) || empty($query->query['name'])) { |
|
| 112 | 112 | return; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | // Add our own post type to the query. |
| 116 | - $post_type = is_array( $query->get( 'post_type' ) ) ? $query->get( 'post_type' ) : array(); |
|
| 117 | - $query->set( 'post_type', array_merge( $post_type, array( 'post', $this->entity_type_service->get_post_type(), 'page' ) ) ); |
|
| 116 | + $post_type = is_array($query->get('post_type')) ? $query->get('post_type') : array(); |
|
| 117 | + $query->set('post_type', array_merge($post_type, array('post', $this->entity_type_service->get_post_type(), 'page'))); |
|
| 118 | 118 | |
| 119 | 119 | } |
| 120 | 120 | |
@@ -129,19 +129,19 @@ discard block |
||
| 129 | 129 | * |
| 130 | 130 | * @return bool Whether the slug is bad. |
| 131 | 131 | */ |
| 132 | - public function wp_unique_post_slug_is_bad_flat_slug( $bad_slug, $slug, $post_type ) { |
|
| 132 | + public function wp_unique_post_slug_is_bad_flat_slug($bad_slug, $slug, $post_type) { |
|
| 133 | 133 | |
| 134 | 134 | // The list of post types that might have conflicting slugs. |
| 135 | - $post_types = array( 'post', 'page', $this->entity_type_service->get_post_type() ); |
|
| 135 | + $post_types = array('post', 'page', $this->entity_type_service->get_post_type()); |
|
| 136 | 136 | |
| 137 | 137 | // Ignore post types different from the ones we need to check. |
| 138 | - if ( ! in_array( $post_type, $post_types ) ) { |
|
| 138 | + if ( ! in_array($post_type, $post_types)) { |
|
| 139 | 139 | return $bad_slug; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - $exists = $this->slug_exists( $slug, array_diff( $post_types, array( $post_type ) ) ); |
|
| 142 | + $exists = $this->slug_exists($slug, array_diff($post_types, array($post_type))); |
|
| 143 | 143 | |
| 144 | - $this->log->debug( "[ exists :: " . ( $exists ? "yes" : "no" ) . " ]" ); |
|
| 144 | + $this->log->debug("[ exists :: ".($exists ? "yes" : "no")." ]"); |
|
| 145 | 145 | |
| 146 | 146 | return $exists; |
| 147 | 147 | } |
@@ -158,17 +158,17 @@ discard block |
||
| 158 | 158 | * |
| 159 | 159 | * @return bool Whether the slug is bad. |
| 160 | 160 | */ |
| 161 | - public function wp_unique_post_slug_is_bad_hierarchical_slug( $bad_slug, $slug, $post_type, $post_parent ) { |
|
| 161 | + public function wp_unique_post_slug_is_bad_hierarchical_slug($bad_slug, $slug, $post_type, $post_parent) { |
|
| 162 | 162 | |
| 163 | 163 | // We only care about pages here. |
| 164 | - if ( 'page' !== $post_type ) { |
|
| 164 | + if ('page' !== $post_type) { |
|
| 165 | 165 | return $bad_slug; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | // We redirect the call to the flat hook, this means that this check is going to solve also the 6-years old issue |
| 169 | 169 | // about overlapping slugs among pages and posts: |
| 170 | 170 | // https://core.trac.wordpress.org/ticket/13459 |
| 171 | - return $this->wp_unique_post_slug_is_bad_flat_slug( $bad_slug, $slug, $post_type ); |
|
| 171 | + return $this->wp_unique_post_slug_is_bad_flat_slug($bad_slug, $slug, $post_type); |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -181,13 +181,13 @@ discard block |
||
| 181 | 181 | * |
| 182 | 182 | * @return bool True if the slug exists, otherwise false. |
| 183 | 183 | */ |
| 184 | - private function slug_exists( $slug, $post_types ) { |
|
| 184 | + private function slug_exists($slug, $post_types) { |
|
| 185 | 185 | global $wpdb; |
| 186 | 186 | |
| 187 | 187 | // Post slugs must be unique across all posts. |
| 188 | - $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ('" . implode( "', '", array_map( 'esc_sql', $post_types ) ) . "') LIMIT 1"; |
|
| 188 | + $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ('".implode("', '", array_map('esc_sql', $post_types))."') LIMIT 1"; |
|
| 189 | 189 | |
| 190 | - return null !== $wpdb->get_var( $wpdb->prepare( $check_sql, $slug ) ); |
|
| 190 | + return null !== $wpdb->get_var($wpdb->prepare($check_sql, $slug)); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | } |
@@ -5,103 +5,103 @@ discard block |
||
| 5 | 5 | */ |
| 6 | 6 | function wl_core_install_entity_type_data() { |
| 7 | 7 | |
| 8 | - // global $wl_logger; |
|
| 9 | - // $wl_logger->trace( 'Installing entity type data...' ); |
|
| 8 | + // global $wl_logger; |
|
| 9 | + // $wl_logger->trace( 'Installing entity type data...' ); |
|
| 10 | 10 | |
| 11 | - // Ensure the custom type and the taxonomy are registered. |
|
| 11 | + // Ensure the custom type and the taxonomy are registered. |
|
| 12 | 12 | // wl_entity_type_register(); |
| 13 | - Wordlift_Entity_Type_Service::get_instance()->register(); |
|
| 14 | - |
|
| 15 | - wl_entity_type_taxonomy_register(); |
|
| 16 | - // Ensure the custom taxonomy for dbpedia topics is registered |
|
| 17 | - Wordlift_Topic_Taxonomy_Service::get_instance()->init(); |
|
| 18 | - |
|
| 19 | - // Set the taxonomy data. |
|
| 20 | - // Note: parent types must be defined before child types. |
|
| 21 | - $terms = array( |
|
| 22 | - 'thing' => array( |
|
| 23 | - 'label' => 'Thing', |
|
| 24 | - 'description' => 'A generic thing (something that doesn\'t fit in the previous definitions.', |
|
| 25 | - ), |
|
| 26 | - 'creative-work' => array( |
|
| 27 | - 'label' => 'CreativeWork', |
|
| 28 | - 'description' => 'A creative work (or a Music Album).', |
|
| 29 | - 'parents' => array( 'thing' ), // give term slug as parent |
|
| 30 | - ), |
|
| 31 | - 'event' => array( |
|
| 32 | - 'label' => 'Event', |
|
| 33 | - 'description' => 'An event.', |
|
| 34 | - 'parents' => array( 'thing' ), |
|
| 35 | - ), |
|
| 36 | - 'organization' => array( |
|
| 37 | - 'label' => 'Organization', |
|
| 38 | - 'description' => 'An organization, including a government or a newspaper.', |
|
| 39 | - 'parents' => array( 'thing' ), |
|
| 40 | - ), |
|
| 41 | - 'person' => array( |
|
| 42 | - 'label' => 'Person', |
|
| 43 | - 'description' => 'A person (or a music artist).', |
|
| 44 | - 'parents' => array( 'thing' ), |
|
| 45 | - ), |
|
| 46 | - 'place' => array( |
|
| 47 | - 'label' => 'Place', |
|
| 48 | - 'description' => 'A place.', |
|
| 49 | - 'parents' => array( 'thing' ), |
|
| 50 | - ), |
|
| 51 | - 'localbusiness' => array( |
|
| 52 | - 'label' => 'LocalBusiness', |
|
| 53 | - 'description' => 'A local business.', |
|
| 54 | - 'parents' => array( 'place', 'organization' ), |
|
| 55 | - ), |
|
| 56 | - ); |
|
| 57 | - |
|
| 58 | - foreach ( $terms as $slug => $term ) { |
|
| 59 | - |
|
| 60 | - // Create the term if it does not exist, then get its ID |
|
| 61 | - $term_id = term_exists( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 62 | - |
|
| 63 | - if ( $term_id == 0 || is_null( $term_id ) ) { |
|
| 64 | - $result = wp_insert_term( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 65 | - } else { |
|
| 66 | - $term_id = $term_id['term_id']; |
|
| 67 | - $result = get_term( $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A ); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - // Check for errors. |
|
| 71 | - if ( is_wp_error( $result ) ) { |
|
| 72 | - wl_write_log( 'wl_install_entity_type_data [ ' . $result->get_error_message() . ' ]' ); |
|
| 73 | - continue; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - // Check if 'parent' corresponds to an actual term and get its ID. |
|
| 77 | - if ( ! isset( $term['parents'] ) ) { |
|
| 78 | - $term['parents'] = array(); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - $parent_ids = array(); |
|
| 82 | - foreach ( $term['parents'] as $parent_slug ) { |
|
| 83 | - $parent_id = get_term_by( 'slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 84 | - $parent_ids[] = intval( $parent_id->term_id ); // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // Define a parent in the WP taxonomy style (not important for WL) |
|
| 88 | - if ( empty( $parent_ids ) ) { |
|
| 89 | - // No parent |
|
| 90 | - $parent_id = 0; |
|
| 91 | - } else { |
|
| 92 | - // Get first parent |
|
| 93 | - $parent_id = $parent_ids[0]; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - // Update term with description, slug and parent |
|
| 97 | - wp_update_term( $result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array( |
|
| 98 | - 'name' => $term['label'], |
|
| 99 | - 'slug' => $slug, |
|
| 100 | - 'description' => $term['description'], |
|
| 101 | - 'parent' => $parent_id // We give to WP taxonomy just one parent. TODO: see if can give more than one |
|
| 102 | - ) ); |
|
| 103 | - |
|
| 104 | - } |
|
| 13 | + Wordlift_Entity_Type_Service::get_instance()->register(); |
|
| 14 | + |
|
| 15 | + wl_entity_type_taxonomy_register(); |
|
| 16 | + // Ensure the custom taxonomy for dbpedia topics is registered |
|
| 17 | + Wordlift_Topic_Taxonomy_Service::get_instance()->init(); |
|
| 18 | + |
|
| 19 | + // Set the taxonomy data. |
|
| 20 | + // Note: parent types must be defined before child types. |
|
| 21 | + $terms = array( |
|
| 22 | + 'thing' => array( |
|
| 23 | + 'label' => 'Thing', |
|
| 24 | + 'description' => 'A generic thing (something that doesn\'t fit in the previous definitions.', |
|
| 25 | + ), |
|
| 26 | + 'creative-work' => array( |
|
| 27 | + 'label' => 'CreativeWork', |
|
| 28 | + 'description' => 'A creative work (or a Music Album).', |
|
| 29 | + 'parents' => array( 'thing' ), // give term slug as parent |
|
| 30 | + ), |
|
| 31 | + 'event' => array( |
|
| 32 | + 'label' => 'Event', |
|
| 33 | + 'description' => 'An event.', |
|
| 34 | + 'parents' => array( 'thing' ), |
|
| 35 | + ), |
|
| 36 | + 'organization' => array( |
|
| 37 | + 'label' => 'Organization', |
|
| 38 | + 'description' => 'An organization, including a government or a newspaper.', |
|
| 39 | + 'parents' => array( 'thing' ), |
|
| 40 | + ), |
|
| 41 | + 'person' => array( |
|
| 42 | + 'label' => 'Person', |
|
| 43 | + 'description' => 'A person (or a music artist).', |
|
| 44 | + 'parents' => array( 'thing' ), |
|
| 45 | + ), |
|
| 46 | + 'place' => array( |
|
| 47 | + 'label' => 'Place', |
|
| 48 | + 'description' => 'A place.', |
|
| 49 | + 'parents' => array( 'thing' ), |
|
| 50 | + ), |
|
| 51 | + 'localbusiness' => array( |
|
| 52 | + 'label' => 'LocalBusiness', |
|
| 53 | + 'description' => 'A local business.', |
|
| 54 | + 'parents' => array( 'place', 'organization' ), |
|
| 55 | + ), |
|
| 56 | + ); |
|
| 57 | + |
|
| 58 | + foreach ( $terms as $slug => $term ) { |
|
| 59 | + |
|
| 60 | + // Create the term if it does not exist, then get its ID |
|
| 61 | + $term_id = term_exists( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 62 | + |
|
| 63 | + if ( $term_id == 0 || is_null( $term_id ) ) { |
|
| 64 | + $result = wp_insert_term( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 65 | + } else { |
|
| 66 | + $term_id = $term_id['term_id']; |
|
| 67 | + $result = get_term( $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A ); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + // Check for errors. |
|
| 71 | + if ( is_wp_error( $result ) ) { |
|
| 72 | + wl_write_log( 'wl_install_entity_type_data [ ' . $result->get_error_message() . ' ]' ); |
|
| 73 | + continue; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + // Check if 'parent' corresponds to an actual term and get its ID. |
|
| 77 | + if ( ! isset( $term['parents'] ) ) { |
|
| 78 | + $term['parents'] = array(); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + $parent_ids = array(); |
|
| 82 | + foreach ( $term['parents'] as $parent_slug ) { |
|
| 83 | + $parent_id = get_term_by( 'slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 84 | + $parent_ids[] = intval( $parent_id->term_id ); // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // Define a parent in the WP taxonomy style (not important for WL) |
|
| 88 | + if ( empty( $parent_ids ) ) { |
|
| 89 | + // No parent |
|
| 90 | + $parent_id = 0; |
|
| 91 | + } else { |
|
| 92 | + // Get first parent |
|
| 93 | + $parent_id = $parent_ids[0]; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + // Update term with description, slug and parent |
|
| 97 | + wp_update_term( $result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array( |
|
| 98 | + 'name' => $term['label'], |
|
| 99 | + 'slug' => $slug, |
|
| 100 | + 'description' => $term['description'], |
|
| 101 | + 'parent' => $parent_id // We give to WP taxonomy just one parent. TODO: see if can give more than one |
|
| 102 | + ) ); |
|
| 103 | + |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | 106 | } |
| 107 | 107 | |
@@ -110,16 +110,16 @@ discard block |
||
| 110 | 110 | */ |
| 111 | 111 | function wl_core_install_create_relation_instance_table() { |
| 112 | 112 | |
| 113 | - global $wpdb; |
|
| 114 | - // global $wl_db_version; |
|
| 115 | - $installed_version = get_option( "wl_db_version" ); |
|
| 113 | + global $wpdb; |
|
| 114 | + // global $wl_db_version; |
|
| 115 | + $installed_version = get_option( "wl_db_version" ); |
|
| 116 | 116 | |
| 117 | - if ( $installed_version != WL_DB_VERSION ) { |
|
| 118 | - $table_name = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME; |
|
| 119 | - $charset_collate = $wpdb->get_charset_collate(); |
|
| 117 | + if ( $installed_version != WL_DB_VERSION ) { |
|
| 118 | + $table_name = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME; |
|
| 119 | + $charset_collate = $wpdb->get_charset_collate(); |
|
| 120 | 120 | |
| 121 | - // Sql statement for the relation instances custom table |
|
| 122 | - $sql = <<<EOF |
|
| 121 | + // Sql statement for the relation instances custom table |
|
| 122 | + $sql = <<<EOF |
|
| 123 | 123 | CREATE TABLE $table_name ( |
| 124 | 124 | id int(11) NOT NULL AUTO_INCREMENT, |
| 125 | 125 | subject_id int(11) NOT NULL, |
@@ -131,14 +131,14 @@ discard block |
||
| 131 | 131 | ) $charset_collate; |
| 132 | 132 | EOF; |
| 133 | 133 | |
| 134 | - // @see: https://codex.wordpress.org/Creating_Tables_with_Plugins |
|
| 135 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
| 136 | - $results = dbDelta( $sql ); |
|
| 134 | + // @see: https://codex.wordpress.org/Creating_Tables_with_Plugins |
|
| 135 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
| 136 | + $results = dbDelta( $sql ); |
|
| 137 | 137 | |
| 138 | - wl_write_log( $results ); |
|
| 138 | + wl_write_log( $results ); |
|
| 139 | 139 | |
| 140 | - update_option( "wl_db_version", WL_DB_VERSION ); |
|
| 141 | - } |
|
| 140 | + update_option( "wl_db_version", WL_DB_VERSION ); |
|
| 141 | + } |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
@@ -146,15 +146,15 @@ discard block |
||
| 146 | 146 | */ |
| 147 | 147 | function wl_core_install() { |
| 148 | 148 | |
| 149 | - // Create a blank application key if there is none |
|
| 150 | - $key = wl_configuration_get_key(); |
|
| 151 | - if ( empty( $key ) ) { |
|
| 152 | - wl_configuration_set_key( '' ); |
|
| 153 | - } |
|
| 149 | + // Create a blank application key if there is none |
|
| 150 | + $key = wl_configuration_get_key(); |
|
| 151 | + if ( empty( $key ) ) { |
|
| 152 | + wl_configuration_set_key( '' ); |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - wl_core_install_entity_type_data(); |
|
| 156 | - wl_core_install_create_relation_instance_table(); |
|
| 157 | - flush_rewrite_rules(); |
|
| 155 | + wl_core_install_entity_type_data(); |
|
| 156 | + wl_core_install_create_relation_instance_table(); |
|
| 157 | + flush_rewrite_rules(); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | // Installation Hook |
@@ -162,9 +162,9 @@ discard block |
||
| 162 | 162 | |
| 163 | 163 | // Check db status on automated plugins updates |
| 164 | 164 | function wl_core_update_db_check() { |
| 165 | - if ( get_site_option( 'wl_db_version' ) != WL_DB_VERSION ) { |
|
| 166 | - wl_core_install_create_relation_instance_table(); |
|
| 167 | - } |
|
| 165 | + if ( get_site_option( 'wl_db_version' ) != WL_DB_VERSION ) { |
|
| 166 | + wl_core_install_create_relation_instance_table(); |
|
| 167 | + } |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | add_action( 'plugins_loaded', 'wl_core_update_db_check' ); |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | // Define the default entity type slug if it's not defined already. The entity type slug is used in permalinks. |
| 4 | -defined( 'WL_ENTITY_TYPE_SLUG' ) || define( 'WL_ENTITY_TYPE_SLUG', Wordlift_Entity_Service::TYPE_NAME ); |
|
| 4 | +defined('WL_ENTITY_TYPE_SLUG') || define('WL_ENTITY_TYPE_SLUG', Wordlift_Entity_Service::TYPE_NAME); |
|
| 5 | 5 | |
| 6 | 6 | /** |
| 7 | 7 | * Provide entity-related services. |
@@ -158,9 +158,9 @@ discard block |
||
| 158 | 158 | * |
| 159 | 159 | * @param \Wordlift_UI_Service $ui_service The UI service. |
| 160 | 160 | */ |
| 161 | - public function __construct( $ui_service, $schema_service, $notice_service ) { |
|
| 161 | + public function __construct($ui_service, $schema_service, $notice_service) { |
|
| 162 | 162 | |
| 163 | - $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Service' ); |
|
| 163 | + $this->log_service = Wordlift_Log_Service::get_logger('Wordlift_Entity_Service'); |
|
| 164 | 164 | |
| 165 | 165 | // Set the UI service. |
| 166 | 166 | $this->ui_service = $ui_service; |
@@ -209,24 +209,24 @@ discard block |
||
| 209 | 209 | public function get_all_related_to_last_50_published_posts() { |
| 210 | 210 | |
| 211 | 211 | // Global timeline. Get entities from the latest posts. |
| 212 | - $latest_posts_ids = get_posts( array( |
|
| 212 | + $latest_posts_ids = get_posts(array( |
|
| 213 | 213 | 'numberposts' => 50, |
| 214 | 214 | 'fields' => 'ids', //only get post IDs |
| 215 | 215 | 'post_type' => 'post', |
| 216 | 216 | 'post_status' => 'publish' |
| 217 | - ) ); |
|
| 217 | + )); |
|
| 218 | 218 | |
| 219 | - if ( empty( $latest_posts_ids ) ) { |
|
| 219 | + if (empty($latest_posts_ids)) { |
|
| 220 | 220 | // There are no posts. |
| 221 | 221 | return array(); |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | // Collect entities related to latest posts |
| 225 | 225 | $entity_ids = array(); |
| 226 | - foreach ( $latest_posts_ids as $id ) { |
|
| 227 | - $entity_ids = array_merge( $entity_ids, wl_core_get_related_entity_ids( $id, array( |
|
| 226 | + foreach ($latest_posts_ids as $id) { |
|
| 227 | + $entity_ids = array_merge($entity_ids, wl_core_get_related_entity_ids($id, array( |
|
| 228 | 228 | 'status' => 'publish' |
| 229 | - ) ) ); |
|
| 229 | + ))); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | return $entity_ids; |
@@ -241,9 +241,9 @@ discard block |
||
| 241 | 241 | * |
| 242 | 242 | * @return bool Return true if the post is an entity otherwise false. |
| 243 | 243 | */ |
| 244 | - public function is_entity( $post_id ) { |
|
| 244 | + public function is_entity($post_id) { |
|
| 245 | 245 | |
| 246 | - return ( self::TYPE_NAME === get_post_type( $post_id ) ); |
|
| 246 | + return (self::TYPE_NAME === get_post_type($post_id)); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | /** |
@@ -255,19 +255,19 @@ discard block |
||
| 255 | 255 | * |
| 256 | 256 | * @return string Returns an uri. |
| 257 | 257 | */ |
| 258 | - public function get_classification_scope_for( $post_id ) { |
|
| 258 | + public function get_classification_scope_for($post_id) { |
|
| 259 | 259 | |
| 260 | - if ( FALSE === $this->is_entity( $post_id ) ) { |
|
| 260 | + if (FALSE === $this->is_entity($post_id)) { |
|
| 261 | 261 | return null; |
| 262 | 262 | } |
| 263 | 263 | // Retrieve the entity type |
| 264 | - $entity_type_arr = wl_entity_type_taxonomy_get_type( $post_id ); |
|
| 265 | - $entity_type = str_replace( 'wl-', '', $entity_type_arr[ 'css_class' ] ); |
|
| 264 | + $entity_type_arr = wl_entity_type_taxonomy_get_type($post_id); |
|
| 265 | + $entity_type = str_replace('wl-', '', $entity_type_arr['css_class']); |
|
| 266 | 266 | // Retrieve classification boxes configuration |
| 267 | - $classification_boxes = unserialize( WL_CORE_POST_CLASSIFICATION_BOXES ); |
|
| 268 | - foreach ( $classification_boxes as $cb ) { |
|
| 269 | - if ( in_array( $entity_type , $cb[ 'registeredTypes' ] ) ) { |
|
| 270 | - return $cb[ 'id' ]; |
|
| 267 | + $classification_boxes = unserialize(WL_CORE_POST_CLASSIFICATION_BOXES); |
|
| 268 | + foreach ($classification_boxes as $cb) { |
|
| 269 | + if (in_array($entity_type, $cb['registeredTypes'])) { |
|
| 270 | + return $cb['id']; |
|
| 271 | 271 | } |
| 272 | 272 | } |
| 273 | 273 | // or null |
@@ -290,23 +290,22 @@ discard block |
||
| 290 | 290 | * |
| 291 | 291 | * @return string Returns an uri. |
| 292 | 292 | */ |
| 293 | - public function build_uri( $title, $post_type, $schema_type = NULL, $increment_digit = 0 ) { |
|
| 293 | + public function build_uri($title, $post_type, $schema_type = NULL, $increment_digit = 0) { |
|
| 294 | 294 | |
| 295 | 295 | // Get the entity slug suffix digit |
| 296 | 296 | $suffix_digit = $increment_digit + 1; |
| 297 | 297 | // Get a sanitized uri for a given title |
| 298 | - $entity_slug = ( 0 == $increment_digit ) ? |
|
| 299 | - wl_sanitize_uri_path( $title ) : |
|
| 300 | - wl_sanitize_uri_path( $title . '_'. $suffix_digit ); |
|
| 298 | + $entity_slug = (0 == $increment_digit) ? |
|
| 299 | + wl_sanitize_uri_path($title) : wl_sanitize_uri_path($title.'_'.$suffix_digit); |
|
| 301 | 300 | |
| 302 | 301 | // Compose a candidated uri |
| 303 | - $new_entity_uri = sprintf( '%s/%s/%s', |
|
| 302 | + $new_entity_uri = sprintf('%s/%s/%s', |
|
| 304 | 303 | wl_configuration_get_redlink_dataset_uri(), |
| 305 | 304 | $post_type, |
| 306 | 305 | $entity_slug |
| 307 | 306 | ); |
| 308 | 307 | |
| 309 | - $this->log_service->trace( "Going to check if uri is used [ new_entity_uri :: $new_entity_uri ] [ increment_digit :: $increment_digit ]" ); |
|
| 308 | + $this->log_service->trace("Going to check if uri is used [ new_entity_uri :: $new_entity_uri ] [ increment_digit :: $increment_digit ]"); |
|
| 310 | 309 | |
| 311 | 310 | global $wpdb; |
| 312 | 311 | // Check if the candidated uri already is used |
@@ -317,32 +316,32 @@ discard block |
||
| 317 | 316 | ); |
| 318 | 317 | |
| 319 | 318 | // Perform the query |
| 320 | - $post_id = $wpdb->get_var( $stmt ); |
|
| 319 | + $post_id = $wpdb->get_var($stmt); |
|
| 321 | 320 | |
| 322 | 321 | // If the post does not exist, then the new uri is returned |
| 323 | - if ( ! is_numeric( $post_id ) ) { |
|
| 324 | - $this->log_service->trace( "Going to return uri [ new_entity_uri :: $new_entity_uri ]" ); |
|
| 322 | + if ( ! is_numeric($post_id)) { |
|
| 323 | + $this->log_service->trace("Going to return uri [ new_entity_uri :: $new_entity_uri ]"); |
|
| 325 | 324 | return $new_entity_uri; |
| 326 | 325 | } |
| 327 | 326 | // If schema_type is equal to schema org type of post x, then the new uri is returned |
| 328 | - $schema_post_type = wl_entity_type_taxonomy_get_type( $post_id ); |
|
| 327 | + $schema_post_type = wl_entity_type_taxonomy_get_type($post_id); |
|
| 329 | 328 | |
| 330 | - if ( $schema_type === $schema_post_type[ 'css_class' ] ) { |
|
| 331 | - $this->log_service->trace( "An entity with the same title and type already exists! Return uri [ new_entity_uri :: $new_entity_uri ]" ); |
|
| 329 | + if ($schema_type === $schema_post_type['css_class']) { |
|
| 330 | + $this->log_service->trace("An entity with the same title and type already exists! Return uri [ new_entity_uri :: $new_entity_uri ]"); |
|
| 332 | 331 | return $new_entity_uri; |
| 333 | 332 | } |
| 334 | 333 | |
| 335 | 334 | // Otherwise the same function is called recorsively |
| 336 | - return $this->build_uri( $title, $post_type, $schema_type, ++$increment_digit ); |
|
| 335 | + return $this->build_uri($title, $post_type, $schema_type, ++$increment_digit); |
|
| 337 | 336 | } |
| 338 | 337 | |
| 339 | - public function is_used( $post_id ) { |
|
| 338 | + public function is_used($post_id) { |
|
| 340 | 339 | |
| 341 | - if ( FALSE === $this->is_entity( $post_id ) ) { |
|
| 340 | + if (FALSE === $this->is_entity($post_id)) { |
|
| 342 | 341 | return null; |
| 343 | 342 | } |
| 344 | 343 | // Retrieve the post |
| 345 | - $entity = get_post( $post_id ); |
|
| 344 | + $entity = get_post($post_id); |
|
| 346 | 345 | |
| 347 | 346 | global $wpdb; |
| 348 | 347 | // Retrieve Wordlift relation instances table name |
@@ -355,9 +354,9 @@ discard block |
||
| 355 | 354 | ); |
| 356 | 355 | |
| 357 | 356 | // Perform the query |
| 358 | - $relation_instances = (int) $wpdb->get_var( $stmt ); |
|
| 357 | + $relation_instances = (int) $wpdb->get_var($stmt); |
|
| 359 | 358 | // If there is at least one relation instance for the current entity, then it's used |
| 360 | - if ( 0 < $relation_instances ) { |
|
| 359 | + if (0 < $relation_instances) { |
|
| 361 | 360 | return TRUE; |
| 362 | 361 | } |
| 363 | 362 | |
@@ -365,13 +364,13 @@ discard block |
||
| 365 | 364 | $stmt = $wpdb->prepare( |
| 366 | 365 | "SELECT COUNT(*) FROM $wpdb->postmeta WHERE post_id != %d AND meta_value = %s", |
| 367 | 366 | $entity->ID, |
| 368 | - wl_get_entity_uri( $entity->ID ) |
|
| 367 | + wl_get_entity_uri($entity->ID) |
|
| 369 | 368 | ); |
| 370 | 369 | // Perform the query |
| 371 | - $meta_instances = (int) $wpdb->get_var( $stmt ); |
|
| 370 | + $meta_instances = (int) $wpdb->get_var($stmt); |
|
| 372 | 371 | |
| 373 | 372 | // If there is at least one meta that refers the current entity uri, then current entity is used |
| 374 | - if ( 0 < $meta_instances ) { |
|
| 373 | + if (0 < $meta_instances) { |
|
| 375 | 374 | return TRUE; |
| 376 | 375 | } |
| 377 | 376 | |
@@ -388,9 +387,9 @@ discard block |
||
| 388 | 387 | * |
| 389 | 388 | * @return true if the uri internal to the current dataset otherwise false. |
| 390 | 389 | */ |
| 391 | - public function is_internal_uri( $uri ) { |
|
| 390 | + public function is_internal_uri($uri) { |
|
| 392 | 391 | |
| 393 | - return ( 0 === strrpos( $uri, wl_configuration_get_redlink_dataset_uri() ) ); |
|
| 392 | + return (0 === strrpos($uri, wl_configuration_get_redlink_dataset_uri())); |
|
| 394 | 393 | } |
| 395 | 394 | |
| 396 | 395 | /** |
@@ -402,7 +401,7 @@ discard block |
||
| 402 | 401 | * |
| 403 | 402 | * @return WP_Post|null A WP_Post instance or null if not found. |
| 404 | 403 | */ |
| 405 | - public function get_entity_post_by_uri( $uri ) { |
|
| 404 | + public function get_entity_post_by_uri($uri) { |
|
| 406 | 405 | |
| 407 | 406 | $query_args = array( |
| 408 | 407 | 'posts_per_page' => 1, |
@@ -420,23 +419,23 @@ discard block |
||
| 420 | 419 | // Only if the current uri is not an internal uri |
| 421 | 420 | // entity search is performed also looking at sameAs values |
| 422 | 421 | // This solve issues like https://github.com/insideout10/wordlift-plugin/issues/237 |
| 423 | - if ( !$this->is_internal_uri( $uri ) ) { |
|
| 422 | + if ( ! $this->is_internal_uri($uri)) { |
|
| 424 | 423 | |
| 425 | - $query_args[ 'meta_query' ][ 'relation' ] = 'OR'; |
|
| 426 | - $query_args[ 'meta_query' ][] = array( |
|
| 424 | + $query_args['meta_query']['relation'] = 'OR'; |
|
| 425 | + $query_args['meta_query'][] = array( |
|
| 427 | 426 | 'key' => Wordlift_Schema_Service::FIELD_SAME_AS, |
| 428 | 427 | 'value' => $uri, |
| 429 | 428 | 'compare' => '=' |
| 430 | 429 | ); |
| 431 | 430 | } |
| 432 | 431 | |
| 433 | - $query = new WP_Query( $query_args ); |
|
| 432 | + $query = new WP_Query($query_args); |
|
| 434 | 433 | |
| 435 | 434 | // Get the matching entity posts. |
| 436 | 435 | $posts = $query->get_posts(); |
| 437 | 436 | |
| 438 | 437 | // Return null if no post is found. |
| 439 | - if ( 0 === count( $posts ) ) { |
|
| 438 | + if (0 === count($posts)) { |
|
| 440 | 439 | return null; |
| 441 | 440 | } |
| 442 | 441 | |
@@ -453,18 +452,18 @@ discard block |
||
| 453 | 452 | * @param WP_Post $post Post object. |
| 454 | 453 | * @param bool $update Whether this is an existing post being updated or not. |
| 455 | 454 | */ |
| 456 | - public function save_post( $post_id, $post, $update ) { |
|
| 455 | + public function save_post($post_id, $post, $update) { |
|
| 457 | 456 | |
| 458 | 457 | // If it's not an entity, return. |
| 459 | - if ( ! $this->is_entity( $post_id ) ) { |
|
| 458 | + if ( ! $this->is_entity($post_id)) { |
|
| 460 | 459 | return; |
| 461 | 460 | } |
| 462 | 461 | |
| 463 | 462 | // Get the alt labels from the request (or empty array). |
| 464 | - $alt_labels = isset( $_REQUEST['wl_alternative_label'] ) ? $_REQUEST['wl_alternative_label'] : array(); |
|
| 463 | + $alt_labels = isset($_REQUEST['wl_alternative_label']) ? $_REQUEST['wl_alternative_label'] : array(); |
|
| 465 | 464 | |
| 466 | 465 | // Set the alternative labels. |
| 467 | - $this->set_alternative_labels( $post_id, $alt_labels ); |
|
| 466 | + $this->set_alternative_labels($post_id, $alt_labels); |
|
| 468 | 467 | |
| 469 | 468 | } |
| 470 | 469 | |
@@ -476,22 +475,22 @@ discard block |
||
| 476 | 475 | * @param int $post_id The post id. |
| 477 | 476 | * @param array $alt_labels An array of labels. |
| 478 | 477 | */ |
| 479 | - public function set_alternative_labels( $post_id, $alt_labels ) { |
|
| 478 | + public function set_alternative_labels($post_id, $alt_labels) { |
|
| 480 | 479 | |
| 481 | 480 | // Force $alt_labels to be an array |
| 482 | - if( !is_array( $alt_labels ) ) { |
|
| 483 | - $alt_labels = array( $alt_labels ); |
|
| 481 | + if ( ! is_array($alt_labels)) { |
|
| 482 | + $alt_labels = array($alt_labels); |
|
| 484 | 483 | } |
| 485 | 484 | |
| 486 | - $this->log_service->debug( "Setting alternative labels [ post id :: $post_id ][ alt labels :: " . implode( ',', $alt_labels ) . " ]" ); |
|
| 485 | + $this->log_service->debug("Setting alternative labels [ post id :: $post_id ][ alt labels :: ".implode(',', $alt_labels)." ]"); |
|
| 487 | 486 | |
| 488 | 487 | // Delete all the existing alternate labels. |
| 489 | - delete_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY ); |
|
| 488 | + delete_post_meta($post_id, self::ALTERNATIVE_LABEL_META_KEY); |
|
| 490 | 489 | |
| 491 | 490 | // Set the alternative labels. |
| 492 | - foreach ( $alt_labels as $alt_label ) { |
|
| 493 | - if ( ! empty( $alt_label ) ) { |
|
| 494 | - add_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY, $alt_label ); |
|
| 491 | + foreach ($alt_labels as $alt_label) { |
|
| 492 | + if ( ! empty($alt_label)) { |
|
| 493 | + add_post_meta($post_id, self::ALTERNATIVE_LABEL_META_KEY, $alt_label); |
|
| 495 | 494 | } |
| 496 | 495 | } |
| 497 | 496 | |
@@ -506,9 +505,9 @@ discard block |
||
| 506 | 505 | * |
| 507 | 506 | * @return mixed An array of alternative labels. |
| 508 | 507 | */ |
| 509 | - public function get_alternative_labels( $post_id ) { |
|
| 508 | + public function get_alternative_labels($post_id) { |
|
| 510 | 509 | |
| 511 | - return get_post_meta( $post_id, self::ALTERNATIVE_LABEL_META_KEY ); |
|
| 510 | + return get_post_meta($post_id, self::ALTERNATIVE_LABEL_META_KEY); |
|
| 512 | 511 | } |
| 513 | 512 | |
| 514 | 513 | /** |
@@ -518,25 +517,25 @@ discard block |
||
| 518 | 517 | * |
| 519 | 518 | * @param WP_Post $post Post object. |
| 520 | 519 | */ |
| 521 | - public function edit_form_before_permalink( $post ) { |
|
| 520 | + public function edit_form_before_permalink($post) { |
|
| 522 | 521 | |
| 523 | 522 | // If it's not an entity, return. |
| 524 | - if ( ! $this->is_entity( $post->ID ) ) { |
|
| 523 | + if ( ! $this->is_entity($post->ID)) { |
|
| 525 | 524 | return; |
| 526 | 525 | } |
| 527 | 526 | |
| 528 | 527 | // Print the input template. |
| 529 | - $this->ui_service->print_template( 'wl-tmpl-alternative-label-input', $this->get_alternative_label_input() ); |
|
| 528 | + $this->ui_service->print_template('wl-tmpl-alternative-label-input', $this->get_alternative_label_input()); |
|
| 530 | 529 | |
| 531 | 530 | // Print all the currently set alternative labels. |
| 532 | - foreach ( $this->get_alternative_labels( $post->ID ) as $alt_label ) { |
|
| 531 | + foreach ($this->get_alternative_labels($post->ID) as $alt_label) { |
|
| 533 | 532 | |
| 534 | - echo $this->get_alternative_label_input( $alt_label ); |
|
| 533 | + echo $this->get_alternative_label_input($alt_label); |
|
| 535 | 534 | |
| 536 | 535 | }; |
| 537 | 536 | |
| 538 | 537 | // Print the button. |
| 539 | - $this->ui_service->print_button( 'wl-add-alternative-labels-button', __( 'Add more titles', 'wordlift' ) ); |
|
| 538 | + $this->ui_service->print_button('wl-add-alternative-labels-button', __('Add more titles', 'wordlift')); |
|
| 540 | 539 | |
| 541 | 540 | } |
| 542 | 541 | |
@@ -550,32 +549,32 @@ discard block |
||
| 550 | 549 | public function in_admin_header() { |
| 551 | 550 | |
| 552 | 551 | // Return safely if get_current_screen() is not defined (yet) |
| 553 | - if ( FALSE === function_exists( 'get_current_screen' ) ) { |
|
| 552 | + if (FALSE === function_exists('get_current_screen')) { |
|
| 554 | 553 | return; |
| 555 | 554 | } |
| 556 | 555 | |
| 557 | 556 | $screen = get_current_screen(); |
| 558 | 557 | // If there is any valid screen nothing to do |
| 559 | - if ( NULL === $screen ) { |
|
| 558 | + if (NULL === $screen) { |
|
| 560 | 559 | return $clauses; |
| 561 | 560 | } |
| 562 | 561 | |
| 563 | 562 | // If you're not in the entity post edit page, return. |
| 564 | - if ( self::TYPE_NAME !== $screen->id ) { |
|
| 563 | + if (self::TYPE_NAME !== $screen->id) { |
|
| 565 | 564 | return; |
| 566 | 565 | } |
| 567 | 566 | // Retrieve the current global post |
| 568 | 567 | global $post; |
| 569 | 568 | // If it's not an entity, return. |
| 570 | - if ( ! $this->is_entity( $post->ID ) ) { |
|
| 569 | + if ( ! $this->is_entity($post->ID)) { |
|
| 571 | 570 | return; |
| 572 | 571 | } |
| 573 | 572 | // Retrieve an updated rating for the current entity |
| 574 | - $rating = $this->get_rating_for( $post->ID, true ); |
|
| 573 | + $rating = $this->get_rating_for($post->ID, true); |
|
| 575 | 574 | // If there is at least 1 warning |
| 576 | - if ( isset( $rating[ 'warnings' ] ) && 0 < count( $rating[ 'warnings' ] ) ) { |
|
| 575 | + if (isset($rating['warnings']) && 0 < count($rating['warnings'])) { |
|
| 577 | 576 | // TODO - Pass Wordlift_Notice_Service trough the service constructor |
| 578 | - $this->notice_service->add_suggestion( $rating[ 'warnings' ] ); |
|
| 577 | + $this->notice_service->add_suggestion($rating['warnings']); |
|
| 579 | 578 | } |
| 580 | 579 | |
| 581 | 580 | } |
@@ -589,19 +588,19 @@ discard block |
||
| 589 | 588 | * |
| 590 | 589 | * @return int An array representing the rating obj. |
| 591 | 590 | */ |
| 592 | - public function set_rating_for( $post_id ) { |
|
| 591 | + public function set_rating_for($post_id) { |
|
| 593 | 592 | |
| 594 | 593 | // Calculate rating for the given post |
| 595 | - $rating = $this->calculate_rating_for( $post_id ); |
|
| 594 | + $rating = $this->calculate_rating_for($post_id); |
|
| 596 | 595 | // Store the rating on db as post meta |
| 597 | 596 | // Please notice that RATING_RAW_SCORE_META_KEY |
| 598 | 597 | // is saved on a different meta to allow score sorting |
| 599 | 598 | // Both meta are managed as unique |
| 600 | 599 | // https://codex.wordpress.org/Function_Reference/update_post_meta |
| 601 | - update_post_meta( $post_id, self::RATING_RAW_SCORE_META_KEY, $rating[ 'raw_score' ] ); |
|
| 602 | - update_post_meta( $post_id, self::RATING_WARNINGS_META_KEY, $rating[ 'warnings' ] ); |
|
| 600 | + update_post_meta($post_id, self::RATING_RAW_SCORE_META_KEY, $rating['raw_score']); |
|
| 601 | + update_post_meta($post_id, self::RATING_WARNINGS_META_KEY, $rating['warnings']); |
|
| 603 | 602 | |
| 604 | - $this->log_service->trace( sprintf( "Rating set for [ post_id :: $post_id ] [ rating :: %s ]", $rating[ 'raw_score' ] ) ); |
|
| 603 | + $this->log_service->trace(sprintf("Rating set for [ post_id :: $post_id ] [ rating :: %s ]", $rating['raw_score'])); |
|
| 605 | 604 | |
| 606 | 605 | // Finally returns the rating |
| 607 | 606 | return $rating; |
@@ -616,27 +615,27 @@ discard block |
||
| 616 | 615 | * |
| 617 | 616 | * @return int An array representing the rating obj. |
| 618 | 617 | */ |
| 619 | - public function get_rating_for( $post_id, $force_reload = false ) { |
|
| 618 | + public function get_rating_for($post_id, $force_reload = false) { |
|
| 620 | 619 | |
| 621 | 620 | // If forced reload is required or rating is missing .. |
| 622 | - if ( $force_reload ) { |
|
| 623 | - $this->log_service->trace( "Force rating reload [ post_id :: $post_id ]" ); |
|
| 624 | - return $this->set_rating_for( $post_id ); |
|
| 621 | + if ($force_reload) { |
|
| 622 | + $this->log_service->trace("Force rating reload [ post_id :: $post_id ]"); |
|
| 623 | + return $this->set_rating_for($post_id); |
|
| 625 | 624 | } |
| 626 | 625 | |
| 627 | - $current_raw_score = get_post_meta( $post_id, self::RATING_RAW_SCORE_META_KEY, true ); |
|
| 626 | + $current_raw_score = get_post_meta($post_id, self::RATING_RAW_SCORE_META_KEY, true); |
|
| 628 | 627 | |
| 629 | - if ( ! is_numeric( $current_raw_score ) ) { |
|
| 630 | - $this->log_service->trace( "Rating missing for [ post_id :: $post_id ] [ current_raw_score :: $current_raw_score ]" ); |
|
| 631 | - return $this->set_rating_for( $post_id ); |
|
| 628 | + if ( ! is_numeric($current_raw_score)) { |
|
| 629 | + $this->log_service->trace("Rating missing for [ post_id :: $post_id ] [ current_raw_score :: $current_raw_score ]"); |
|
| 630 | + return $this->set_rating_for($post_id); |
|
| 632 | 631 | } |
| 633 | - $current_warnings = get_post_meta( $post_id, self::RATING_WARNINGS_META_KEY, true ); |
|
| 632 | + $current_warnings = get_post_meta($post_id, self::RATING_WARNINGS_META_KEY, true); |
|
| 634 | 633 | |
| 635 | 634 | // Finally return score and warnings |
| 636 | 635 | return array( |
| 637 | 636 | 'raw_score' => $current_raw_score, |
| 638 | - 'traffic_light_score' => $this->convert_raw_score_to_traffic_light( $current_raw_score ), |
|
| 639 | - 'percentage_score' => $this->convert_raw_score_to_percentage( $current_raw_score ), |
|
| 637 | + 'traffic_light_score' => $this->convert_raw_score_to_traffic_light($current_raw_score), |
|
| 638 | + 'percentage_score' => $this->convert_raw_score_to_percentage($current_raw_score), |
|
| 640 | 639 | 'warnings' => $current_warnings, |
| 641 | 640 | ); |
| 642 | 641 | |
@@ -661,44 +660,39 @@ discard block |
||
| 661 | 660 | * |
| 662 | 661 | * @return int An array representing the rating obj. |
| 663 | 662 | */ |
| 664 | - public function calculate_rating_for( $post_id ) { |
|
| 663 | + public function calculate_rating_for($post_id) { |
|
| 665 | 664 | |
| 666 | 665 | // If it's not an entity, return. |
| 667 | - if ( ! $this->is_entity( $post_id ) ) { |
|
| 666 | + if ( ! $this->is_entity($post_id)) { |
|
| 668 | 667 | return; |
| 669 | 668 | } |
| 670 | 669 | // Retrieve the post object |
| 671 | - $post = get_post( $post_id ); |
|
| 670 | + $post = get_post($post_id); |
|
| 672 | 671 | // Rating value |
| 673 | 672 | $score = 0; |
| 674 | 673 | // Store warning messages |
| 675 | 674 | $warnings = array(); |
| 676 | 675 | |
| 677 | 676 | // Is the current entity related to at least 1 post? |
| 678 | - ( 0 < count( wl_core_get_related_post_ids( $post->ID ) ) ) ? |
|
| 679 | - $score++ : |
|
| 680 | - array_push( $warnings, __( self::RATING_WARNING_HAS_RELATED_POSTS, 'wordlift' ) ); |
|
| 677 | + (0 < count(wl_core_get_related_post_ids($post->ID))) ? |
|
| 678 | + $score++ : array_push($warnings, __(self::RATING_WARNING_HAS_RELATED_POSTS, 'wordlift')); |
|
| 681 | 679 | |
| 682 | 680 | // Is the post content not empty? |
| 683 | - ( ! empty( $post->post_content ) ) ? |
|
| 684 | - $score++ : |
|
| 685 | - array_push( $warnings, __( self::RATING_WARNING_HAS_CONTENT_POST, 'wordlift' ) ); |
|
| 681 | + ( ! empty($post->post_content)) ? |
|
| 682 | + $score++ : array_push($warnings, __(self::RATING_WARNING_HAS_CONTENT_POST, 'wordlift')); |
|
| 686 | 683 | |
| 687 | 684 | // Is the current entity related to at least 1 entity? |
| 688 | 685 | // Was the current entity already disambiguated? |
| 689 | - ( 0 < count( wl_core_get_related_entity_ids( $post->ID ) ) ) ? |
|
| 690 | - $score++ : |
|
| 691 | - array_push( $warnings, __( self::RATING_WARNING_HAS_RELATED_ENTITIES, 'wordlift' ) ); |
|
| 686 | + (0 < count(wl_core_get_related_entity_ids($post->ID))) ? |
|
| 687 | + $score++ : array_push($warnings, __(self::RATING_WARNING_HAS_RELATED_ENTITIES, 'wordlift')); |
|
| 692 | 688 | |
| 693 | 689 | // Is the entity published? |
| 694 | - ( 'publish' === get_post_status( $post->ID ) ) ? |
|
| 695 | - $score++ : |
|
| 696 | - array_push( $warnings, __( self::RATING_WARNING_IS_PUBLISHED, 'wordlift' ) ); |
|
| 690 | + ('publish' === get_post_status($post->ID)) ? |
|
| 691 | + $score++ : array_push($warnings, __(self::RATING_WARNING_IS_PUBLISHED, 'wordlift')); |
|
| 697 | 692 | |
| 698 | 693 | // Has a thumbnail? |
| 699 | - ( has_post_thumbnail( $post->ID ) ) ? |
|
| 700 | - $score++ : |
|
| 701 | - array_push( $warnings, __( self::RATING_WARNING_HAS_THUMBNAIL, 'wordlift' ) ); |
|
| 694 | + (has_post_thumbnail($post->ID)) ? |
|
| 695 | + $score++ : array_push($warnings, __(self::RATING_WARNING_HAS_THUMBNAIL, 'wordlift')); |
|
| 702 | 696 | |
| 703 | 697 | // Get all post meta keys for the current post |
| 704 | 698 | global $wpdb; |
@@ -708,30 +702,27 @@ discard block |
||
| 708 | 702 | |
| 709 | 703 | // Check intersection between available meta keys |
| 710 | 704 | // and expected ones arrays to detect missing values |
| 711 | - $available_meta_keys = $wpdb->get_col( $query ); |
|
| 705 | + $available_meta_keys = $wpdb->get_col($query); |
|
| 712 | 706 | |
| 713 | 707 | // If each expected key is contained in available keys array ... |
| 714 | - ( in_array( Wordlift_Schema_Service::FIELD_SAME_AS, $available_meta_keys ) ) ? |
|
| 715 | - $score++ : |
|
| 716 | - array_push( $warnings, __( self::RATING_WARNING_HAS_SAME_AS, 'wordlift' ) ); |
|
| 708 | + (in_array(Wordlift_Schema_Service::FIELD_SAME_AS, $available_meta_keys)) ? |
|
| 709 | + $score++ : array_push($warnings, __(self::RATING_WARNING_HAS_SAME_AS, 'wordlift')); |
|
| 717 | 710 | |
| 718 | - $schema = wl_entity_type_taxonomy_get_type( $post_id ); |
|
| 711 | + $schema = wl_entity_type_taxonomy_get_type($post_id); |
|
| 719 | 712 | |
| 720 | - $expected_meta_keys = ( null === $schema[ 'custom_fields' ] ) ? |
|
| 721 | - array() : |
|
| 722 | - array_keys( $schema[ 'custom_fields' ] ); |
|
| 713 | + $expected_meta_keys = (null === $schema['custom_fields']) ? |
|
| 714 | + array() : array_keys($schema['custom_fields']); |
|
| 723 | 715 | |
| 724 | - $intersection = array_intersect( $expected_meta_keys, $available_meta_keys ); |
|
| 716 | + $intersection = array_intersect($expected_meta_keys, $available_meta_keys); |
|
| 725 | 717 | // If each expected key is contained in available keys array ... |
| 726 | - ( count( $intersection ) === count( $expected_meta_keys ) ) ? |
|
| 727 | - $score++ : |
|
| 728 | - array_push( $warnings, __( self::RATING_WARNING_HAS_COMPLETED_METADATA, 'wordlift' ) ); |
|
| 718 | + (count($intersection) === count($expected_meta_keys)) ? |
|
| 719 | + $score++ : array_push($warnings, __(self::RATING_WARNING_HAS_COMPLETED_METADATA, 'wordlift')); |
|
| 729 | 720 | |
| 730 | 721 | // Finally return score and warnings |
| 731 | 722 | return array( |
| 732 | 723 | 'raw_score' => $score, |
| 733 | - 'traffic_light_score' => $this->convert_raw_score_to_traffic_light( $score ), |
|
| 734 | - 'percentage_score' => $this->convert_raw_score_to_percentage( $score ), |
|
| 724 | + 'traffic_light_score' => $this->convert_raw_score_to_traffic_light($score), |
|
| 725 | + 'percentage_score' => $this->convert_raw_score_to_percentage($score), |
|
| 735 | 726 | 'warnings' => $warnings, |
| 736 | 727 | ); |
| 737 | 728 | |
@@ -746,12 +737,12 @@ discard block |
||
| 746 | 737 | * |
| 747 | 738 | * @return string The input HTML code. |
| 748 | 739 | */ |
| 749 | - private function convert_raw_score_to_traffic_light( $score ) { |
|
| 740 | + private function convert_raw_score_to_traffic_light($score) { |
|
| 750 | 741 | // RATING_MAX : $score = 3 : x |
| 751 | 742 | // See http://php.net/manual/en/function.round.php |
| 752 | - $rating = round( ( $score * 3 ) / self::get_rating_max(), 0, PHP_ROUND_HALF_UP ); |
|
| 743 | + $rating = round(($score * 3) / self::get_rating_max(), 0, PHP_ROUND_HALF_UP); |
|
| 753 | 744 | // If rating is 0, return 1, otherwise return rating |
| 754 | - return ( 0 == $rating ) ? 1 : $rating; |
|
| 745 | + return (0 == $rating) ? 1 : $rating; |
|
| 755 | 746 | |
| 756 | 747 | } |
| 757 | 748 | |
@@ -764,9 +755,9 @@ discard block |
||
| 764 | 755 | * |
| 765 | 756 | * @return string The input HTML code. |
| 766 | 757 | */ |
| 767 | - public function convert_raw_score_to_percentage( $score ) { |
|
| 758 | + public function convert_raw_score_to_percentage($score) { |
|
| 768 | 759 | // RATING_MAX : $score = 100 : x |
| 769 | - return round( ( $score * 100) / self::get_rating_max(), 0, PHP_ROUND_HALF_UP ); |
|
| 760 | + return round(($score * 100) / self::get_rating_max(), 0, PHP_ROUND_HALF_UP); |
|
| 770 | 761 | } |
| 771 | 762 | |
| 772 | 763 | /** |
@@ -778,8 +769,8 @@ discard block |
||
| 778 | 769 | * |
| 779 | 770 | * @return string The input HTML code. |
| 780 | 771 | */ |
| 781 | - private function get_alternative_label_input( $value = '' ) { |
|
| 772 | + private function get_alternative_label_input($value = '') { |
|
| 782 | 773 | |
| 783 | - return sprintf( self::ALTERNATIVE_LABEL_INPUT_TEMPLATE, esc_attr( $value ), __( 'Delete', 'wordlift' ) ); |
|
| 774 | + return sprintf(self::ALTERNATIVE_LABEL_INPUT_TEMPLATE, esc_attr($value), __('Delete', 'wordlift')); |
|
| 784 | 775 | } |
| 785 | 776 | } |
@@ -7,174 +7,174 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class Wordlift_Topic_Taxonomy_Service { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * The Log service. |
|
| 12 | - * |
|
| 13 | - * @since 3.5.0 |
|
| 14 | - * @access private |
|
| 15 | - * @var \Wordlift_Log_Service $log_service The Log service. |
|
| 16 | - */ |
|
| 17 | - private $log_service; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Taxonomy name. |
|
| 21 | - * |
|
| 22 | - * @since 3.5.0 |
|
| 23 | - */ |
|
| 24 | - const TAXONOMY_NAME = 'wl_topic'; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Taxonomy object type. |
|
| 28 | - * |
|
| 29 | - * @since 3.5.0 |
|
| 30 | - */ |
|
| 31 | - const TAXONOMY_OBJECT_TYPE = 'post'; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Taxonomy slug. |
|
| 35 | - * |
|
| 36 | - * @since 3.5.0 |
|
| 37 | - */ |
|
| 38 | - const TAXONOMY_SLUG = 'wl_topic'; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * A singleton instance of the Wordlift_Topic_Taxonomy_Service service. |
|
| 42 | - * |
|
| 43 | - * @since 3.5.0 |
|
| 44 | - * @access private |
|
| 45 | - * @var \Wordlift_Topic_Taxonomy_Service $instance A singleton instance of Wordlift_Topic_Taxonomy_Service. |
|
| 46 | - */ |
|
| 47 | - private static $instance; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Create a Wordlift_Topic_Taxonomy_Service instance. |
|
| 51 | - * |
|
| 52 | - * @since 3.5.0 |
|
| 53 | - * |
|
| 54 | - */ |
|
| 55 | - public function __construct() { |
|
| 56 | - |
|
| 57 | - $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Service' ); |
|
| 58 | - |
|
| 59 | - // Set the singleton instance. |
|
| 60 | - self::$instance = $this; |
|
| 61 | - |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Get the singleton instance of the Entity service. |
|
| 66 | - * |
|
| 67 | - * @since 3.5.0 |
|
| 68 | - * @return Wordlift_Topic_Taxonomy_Service |
|
| 69 | - */ |
|
| 70 | - public static function get_instance() { |
|
| 71 | - |
|
| 72 | - return self::$instance; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Just register the topic taxonomy. |
|
| 77 | - * |
|
| 78 | - * @since 3.5.0 |
|
| 79 | - * |
|
| 80 | - */ |
|
| 81 | - public function init() { |
|
| 82 | - |
|
| 83 | - // See https://codex.wordpress.org/Function_Reference/register_taxonomy |
|
| 84 | - $labels = array( |
|
| 85 | - 'name' => _x( 'Topics', 'taxonomy general name' ), |
|
| 86 | - 'singular_name' => _x( 'Topic', 'taxonomy singular name' ), |
|
| 87 | - 'search_items' => __( 'Search Topics' ), |
|
| 88 | - 'all_items' => __( 'All Topics' ), |
|
| 89 | - 'parent_item' => __( 'Parent Topic' ), |
|
| 90 | - 'parent_item_colon' => __( 'Parent Topic:' ), |
|
| 91 | - 'edit_item' => __( 'Edit Topic' ), |
|
| 92 | - 'update_item' => __( 'Update Topic' ), |
|
| 93 | - 'add_new_item' => __( 'Add New Topic' ), |
|
| 94 | - 'new_item_name' => __( 'New Topic' ), |
|
| 95 | - 'menu_name' => __( 'Topics' ), |
|
| 96 | - ); |
|
| 97 | - |
|
| 98 | - $capabilities = array( |
|
| 99 | - 'manage_terms' => null, |
|
| 100 | - 'edit_terms' => null, |
|
| 101 | - 'delete_terms' => null, |
|
| 102 | - 'assign_terms' => 'edit_posts' |
|
| 103 | - ); |
|
| 104 | - |
|
| 105 | - $args = array( |
|
| 106 | - 'labels' => $labels, |
|
| 107 | - 'capabilities' => $capabilities, |
|
| 108 | - 'hierarchical' => true, |
|
| 109 | - 'show_admin_column' => false, |
|
| 110 | - 'show_ui' => false, |
|
| 111 | - 'rewrite' => array( |
|
| 112 | - 'slug' => self::TAXONOMY_SLUG |
|
| 113 | - ) |
|
| 114 | - ); |
|
| 115 | - |
|
| 116 | - // Register taxonomy |
|
| 117 | - register_taxonomy( |
|
| 118 | - self::TAXONOMY_NAME, self::TAXONOMY_OBJECT_TYPE, $args |
|
| 119 | - ); |
|
| 120 | - |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Get or create a taxonomy term from a given entity topic. |
|
| 125 | - * |
|
| 126 | - * @since 3.5.0 |
|
| 127 | - * |
|
| 128 | - */ |
|
| 129 | - public function get_or_create_term_from_topic_entity( $topic ) { |
|
| 10 | + /** |
|
| 11 | + * The Log service. |
|
| 12 | + * |
|
| 13 | + * @since 3.5.0 |
|
| 14 | + * @access private |
|
| 15 | + * @var \Wordlift_Log_Service $log_service The Log service. |
|
| 16 | + */ |
|
| 17 | + private $log_service; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Taxonomy name. |
|
| 21 | + * |
|
| 22 | + * @since 3.5.0 |
|
| 23 | + */ |
|
| 24 | + const TAXONOMY_NAME = 'wl_topic'; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Taxonomy object type. |
|
| 28 | + * |
|
| 29 | + * @since 3.5.0 |
|
| 30 | + */ |
|
| 31 | + const TAXONOMY_OBJECT_TYPE = 'post'; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Taxonomy slug. |
|
| 35 | + * |
|
| 36 | + * @since 3.5.0 |
|
| 37 | + */ |
|
| 38 | + const TAXONOMY_SLUG = 'wl_topic'; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * A singleton instance of the Wordlift_Topic_Taxonomy_Service service. |
|
| 42 | + * |
|
| 43 | + * @since 3.5.0 |
|
| 44 | + * @access private |
|
| 45 | + * @var \Wordlift_Topic_Taxonomy_Service $instance A singleton instance of Wordlift_Topic_Taxonomy_Service. |
|
| 46 | + */ |
|
| 47 | + private static $instance; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Create a Wordlift_Topic_Taxonomy_Service instance. |
|
| 51 | + * |
|
| 52 | + * @since 3.5.0 |
|
| 53 | + * |
|
| 54 | + */ |
|
| 55 | + public function __construct() { |
|
| 56 | + |
|
| 57 | + $this->log_service = Wordlift_Log_Service::get_logger( 'Wordlift_Entity_Service' ); |
|
| 58 | + |
|
| 59 | + // Set the singleton instance. |
|
| 60 | + self::$instance = $this; |
|
| 61 | + |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Get the singleton instance of the Entity service. |
|
| 66 | + * |
|
| 67 | + * @since 3.5.0 |
|
| 68 | + * @return Wordlift_Topic_Taxonomy_Service |
|
| 69 | + */ |
|
| 70 | + public static function get_instance() { |
|
| 71 | + |
|
| 72 | + return self::$instance; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Just register the topic taxonomy. |
|
| 77 | + * |
|
| 78 | + * @since 3.5.0 |
|
| 79 | + * |
|
| 80 | + */ |
|
| 81 | + public function init() { |
|
| 82 | + |
|
| 83 | + // See https://codex.wordpress.org/Function_Reference/register_taxonomy |
|
| 84 | + $labels = array( |
|
| 85 | + 'name' => _x( 'Topics', 'taxonomy general name' ), |
|
| 86 | + 'singular_name' => _x( 'Topic', 'taxonomy singular name' ), |
|
| 87 | + 'search_items' => __( 'Search Topics' ), |
|
| 88 | + 'all_items' => __( 'All Topics' ), |
|
| 89 | + 'parent_item' => __( 'Parent Topic' ), |
|
| 90 | + 'parent_item_colon' => __( 'Parent Topic:' ), |
|
| 91 | + 'edit_item' => __( 'Edit Topic' ), |
|
| 92 | + 'update_item' => __( 'Update Topic' ), |
|
| 93 | + 'add_new_item' => __( 'Add New Topic' ), |
|
| 94 | + 'new_item_name' => __( 'New Topic' ), |
|
| 95 | + 'menu_name' => __( 'Topics' ), |
|
| 96 | + ); |
|
| 97 | + |
|
| 98 | + $capabilities = array( |
|
| 99 | + 'manage_terms' => null, |
|
| 100 | + 'edit_terms' => null, |
|
| 101 | + 'delete_terms' => null, |
|
| 102 | + 'assign_terms' => 'edit_posts' |
|
| 103 | + ); |
|
| 104 | + |
|
| 105 | + $args = array( |
|
| 106 | + 'labels' => $labels, |
|
| 107 | + 'capabilities' => $capabilities, |
|
| 108 | + 'hierarchical' => true, |
|
| 109 | + 'show_admin_column' => false, |
|
| 110 | + 'show_ui' => false, |
|
| 111 | + 'rewrite' => array( |
|
| 112 | + 'slug' => self::TAXONOMY_SLUG |
|
| 113 | + ) |
|
| 114 | + ); |
|
| 115 | + |
|
| 116 | + // Register taxonomy |
|
| 117 | + register_taxonomy( |
|
| 118 | + self::TAXONOMY_NAME, self::TAXONOMY_OBJECT_TYPE, $args |
|
| 119 | + ); |
|
| 120 | + |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Get or create a taxonomy term from a given entity topic. |
|
| 125 | + * |
|
| 126 | + * @since 3.5.0 |
|
| 127 | + * |
|
| 128 | + */ |
|
| 129 | + public function get_or_create_term_from_topic_entity( $topic ) { |
|
| 130 | 130 | |
| 131 | - // Define taxonomy term slug |
|
| 132 | - $term_slug = sanitize_title( $topic->post_title ); |
|
| 133 | - // Look for an existing taxonomy term with a given slug |
|
| 134 | - if ( $term = get_term_by( 'slug', $term_slug, self::TAXONOMY_NAME ) ) { |
|
| 135 | - return (int) $term->term_id; |
|
| 136 | - } |
|
| 137 | - // Otherwise create a new term and return it |
|
| 138 | - $result = wp_insert_term( |
|
| 139 | - $topic->post_title, |
|
| 140 | - self::TAXONOMY_NAME, |
|
| 141 | - array( |
|
| 142 | - 'slug' => $term_slug, |
|
| 143 | - 'description' => $topic->post_content |
|
| 144 | - ) |
|
| 145 | - ); |
|
| 146 | - |
|
| 147 | - return (int) $result[ 'term_id' ]; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Set a topic for a given post. |
|
| 152 | - * |
|
| 153 | - * @since 3.5.0 |
|
| 154 | - * |
|
| 155 | - */ |
|
| 156 | - public function set_topic_for( $post_id, $topic_id ) { |
|
| 157 | - // Retrieve the topic entity post |
|
| 158 | - $topic_entity_post = get_post( $topic_id ); |
|
| 159 | - // If current topic does not exist in db false is returned |
|
| 160 | - if ( NULL === $topic_entity_post ) { |
|
| 161 | - return false; |
|
| 162 | - } |
|
| 163 | - // Create the proper taxonomy term if needed |
|
| 164 | - $term_id = $this->get_or_create_term_from_topic_entity( $topic_entity_post ); |
|
| 165 | - // Link the term to the current post |
|
| 166 | - wp_set_post_terms( $post_id, $term_id, self::TAXONOMY_NAME, false ); |
|
| 167 | - return true; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Unlink any topic for a given post. |
|
| 172 | - * |
|
| 173 | - * @since 3.5.0 |
|
| 174 | - * |
|
| 175 | - */ |
|
| 176 | - public function unlink_topic_for( $post_id ) { |
|
| 177 | - wp_delete_object_term_relationships( $post_id, self::TAXONOMY_NAME ); |
|
| 178 | - } |
|
| 131 | + // Define taxonomy term slug |
|
| 132 | + $term_slug = sanitize_title( $topic->post_title ); |
|
| 133 | + // Look for an existing taxonomy term with a given slug |
|
| 134 | + if ( $term = get_term_by( 'slug', $term_slug, self::TAXONOMY_NAME ) ) { |
|
| 135 | + return (int) $term->term_id; |
|
| 136 | + } |
|
| 137 | + // Otherwise create a new term and return it |
|
| 138 | + $result = wp_insert_term( |
|
| 139 | + $topic->post_title, |
|
| 140 | + self::TAXONOMY_NAME, |
|
| 141 | + array( |
|
| 142 | + 'slug' => $term_slug, |
|
| 143 | + 'description' => $topic->post_content |
|
| 144 | + ) |
|
| 145 | + ); |
|
| 146 | + |
|
| 147 | + return (int) $result[ 'term_id' ]; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Set a topic for a given post. |
|
| 152 | + * |
|
| 153 | + * @since 3.5.0 |
|
| 154 | + * |
|
| 155 | + */ |
|
| 156 | + public function set_topic_for( $post_id, $topic_id ) { |
|
| 157 | + // Retrieve the topic entity post |
|
| 158 | + $topic_entity_post = get_post( $topic_id ); |
|
| 159 | + // If current topic does not exist in db false is returned |
|
| 160 | + if ( NULL === $topic_entity_post ) { |
|
| 161 | + return false; |
|
| 162 | + } |
|
| 163 | + // Create the proper taxonomy term if needed |
|
| 164 | + $term_id = $this->get_or_create_term_from_topic_entity( $topic_entity_post ); |
|
| 165 | + // Link the term to the current post |
|
| 166 | + wp_set_post_terms( $post_id, $term_id, self::TAXONOMY_NAME, false ); |
|
| 167 | + return true; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Unlink any topic for a given post. |
|
| 172 | + * |
|
| 173 | + * @since 3.5.0 |
|
| 174 | + * |
|
| 175 | + */ |
|
| 176 | + public function unlink_topic_for( $post_id ) { |
|
| 177 | + wp_delete_object_term_relationships( $post_id, self::TAXONOMY_NAME ); |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | 180 | } |
@@ -6,129 +6,129 @@ |
||
| 6 | 6 | */ |
| 7 | 7 | class Wordlift_Entity_Type_Service { |
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * The entity post type. |
|
| 11 | - * |
|
| 12 | - * @since 3.6.0 |
|
| 13 | - * @access private |
|
| 14 | - * @var string $post_type The entity post type. |
|
| 15 | - */ |
|
| 16 | - private $post_type; |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * The entity type slug. |
|
| 20 | - * |
|
| 21 | - * @since 3.6.0 |
|
| 22 | - * @access private |
|
| 23 | - * @var string $slug The entity type slug. |
|
| 24 | - */ |
|
| 25 | - private $slug; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * A singleton instance of the entity type service. |
|
| 29 | - * |
|
| 30 | - * @since 3.6.0 |
|
| 31 | - * @access private |
|
| 32 | - * @var Wordlift_Entity_Type_Service |
|
| 33 | - */ |
|
| 34 | - private static $instance; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Create an entity type service instance. |
|
| 38 | - * |
|
| 39 | - * @since 3.6.0 |
|
| 40 | - * |
|
| 41 | - * @param string $post_type The post type, e.g. entity. |
|
| 42 | - * @param string $slug The entity type slug, if the slug is empty, the default slug will be used. |
|
| 43 | - */ |
|
| 44 | - public function __construct( $post_type, $slug ) { |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - $this->post_type = $post_type; |
|
| 48 | - |
|
| 49 | - // We cannot assign an empty slug to the register_post_type function, therefore if the slug is empty we default |
|
| 50 | - // to the type name. |
|
| 51 | - $this->slug = $slug ?: $post_type; |
|
| 52 | - |
|
| 53 | - self::$instance = $this; |
|
| 54 | - |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Get the entity type service singleton instance. |
|
| 59 | - * |
|
| 60 | - * @since 3.6.0 |
|
| 61 | - * |
|
| 62 | - * @return Wordlift_Entity_Type_Service The entity type service singleton instance. |
|
| 63 | - */ |
|
| 64 | - public static function get_instance() { |
|
| 65 | - |
|
| 66 | - return self::$instance; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Get the entity type slug. |
|
| 71 | - * |
|
| 72 | - * @since 3.6.0 |
|
| 73 | - * |
|
| 74 | - * @return string The entity type slug. |
|
| 75 | - */ |
|
| 76 | - public function get_slug() { |
|
| 77 | - |
|
| 78 | - return $this->slug; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Get the entity post type name. |
|
| 83 | - * |
|
| 84 | - * @since 3.6.0 |
|
| 85 | - * |
|
| 86 | - * @return string The entity post type. |
|
| 87 | - */ |
|
| 88 | - public function get_post_type() { |
|
| 89 | - |
|
| 90 | - return $this->post_type; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Register the WordLift entity post type. This method is hooked to WordPress' init action. |
|
| 96 | - * |
|
| 97 | - * @since 3.6.0 |
|
| 98 | - */ |
|
| 99 | - public function register() { |
|
| 100 | - |
|
| 101 | - $labels = array( |
|
| 102 | - 'name' => _x( 'Vocabulary', 'post type general name', 'wordlift' ), |
|
| 103 | - 'singular_name' => _x( 'Entity', 'post type singular name', 'wordlift' ), |
|
| 104 | - 'add_new' => _x( 'Add New Entity', 'entity', 'wordlift' ), |
|
| 105 | - 'add_new_item' => __( 'Add New Entity', 'wordlift' ), |
|
| 106 | - 'edit_item' => __( 'Edit Entity', 'wordlift' ), |
|
| 107 | - 'new_item' => __( 'New Entity', 'wordlift' ), |
|
| 108 | - 'all_items' => __( 'All Entities', 'wordlift' ), |
|
| 109 | - 'view_item' => __( 'View Entity', 'wordlift' ), |
|
| 110 | - 'search_items' => __( 'Search in Vocabulary', 'wordlift' ), |
|
| 111 | - 'not_found' => __( 'No entities found', 'wordlift' ), |
|
| 112 | - 'not_found_in_trash' => __( 'No entities found in the Trash', 'wordlift' ), |
|
| 113 | - 'parent_item_colon' => '', |
|
| 114 | - 'menu_name' => __( 'Vocabulary', 'wordlift' ) |
|
| 115 | - ); |
|
| 116 | - |
|
| 117 | - $args = array( |
|
| 118 | - 'labels' => $labels, |
|
| 119 | - 'description' => 'Holds our vocabulary (set of entities) and entity specific data', |
|
| 120 | - 'public' => true, |
|
| 121 | - 'menu_position' => 20, |
|
| 122 | - // after the pages menu. |
|
| 123 | - 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ), |
|
| 124 | - 'has_archive' => true, |
|
| 125 | - 'menu_icon' => WP_CONTENT_URL . '/plugins/wordlift/images/svg/wl-vocabulary-icon.svg', |
|
| 126 | - // Although we define our slug here, we further manage linking to entities using the Wordlift_Entity_Link_Service. |
|
| 127 | - 'rewrite' => array( 'slug' => $this->slug ) |
|
| 128 | - ); |
|
| 129 | - |
|
| 130 | - register_post_type( $this->post_type, $args ); |
|
| 131 | - |
|
| 132 | - } |
|
| 9 | + /** |
|
| 10 | + * The entity post type. |
|
| 11 | + * |
|
| 12 | + * @since 3.6.0 |
|
| 13 | + * @access private |
|
| 14 | + * @var string $post_type The entity post type. |
|
| 15 | + */ |
|
| 16 | + private $post_type; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * The entity type slug. |
|
| 20 | + * |
|
| 21 | + * @since 3.6.0 |
|
| 22 | + * @access private |
|
| 23 | + * @var string $slug The entity type slug. |
|
| 24 | + */ |
|
| 25 | + private $slug; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * A singleton instance of the entity type service. |
|
| 29 | + * |
|
| 30 | + * @since 3.6.0 |
|
| 31 | + * @access private |
|
| 32 | + * @var Wordlift_Entity_Type_Service |
|
| 33 | + */ |
|
| 34 | + private static $instance; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Create an entity type service instance. |
|
| 38 | + * |
|
| 39 | + * @since 3.6.0 |
|
| 40 | + * |
|
| 41 | + * @param string $post_type The post type, e.g. entity. |
|
| 42 | + * @param string $slug The entity type slug, if the slug is empty, the default slug will be used. |
|
| 43 | + */ |
|
| 44 | + public function __construct( $post_type, $slug ) { |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + $this->post_type = $post_type; |
|
| 48 | + |
|
| 49 | + // We cannot assign an empty slug to the register_post_type function, therefore if the slug is empty we default |
|
| 50 | + // to the type name. |
|
| 51 | + $this->slug = $slug ?: $post_type; |
|
| 52 | + |
|
| 53 | + self::$instance = $this; |
|
| 54 | + |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Get the entity type service singleton instance. |
|
| 59 | + * |
|
| 60 | + * @since 3.6.0 |
|
| 61 | + * |
|
| 62 | + * @return Wordlift_Entity_Type_Service The entity type service singleton instance. |
|
| 63 | + */ |
|
| 64 | + public static function get_instance() { |
|
| 65 | + |
|
| 66 | + return self::$instance; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Get the entity type slug. |
|
| 71 | + * |
|
| 72 | + * @since 3.6.0 |
|
| 73 | + * |
|
| 74 | + * @return string The entity type slug. |
|
| 75 | + */ |
|
| 76 | + public function get_slug() { |
|
| 77 | + |
|
| 78 | + return $this->slug; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Get the entity post type name. |
|
| 83 | + * |
|
| 84 | + * @since 3.6.0 |
|
| 85 | + * |
|
| 86 | + * @return string The entity post type. |
|
| 87 | + */ |
|
| 88 | + public function get_post_type() { |
|
| 89 | + |
|
| 90 | + return $this->post_type; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Register the WordLift entity post type. This method is hooked to WordPress' init action. |
|
| 96 | + * |
|
| 97 | + * @since 3.6.0 |
|
| 98 | + */ |
|
| 99 | + public function register() { |
|
| 100 | + |
|
| 101 | + $labels = array( |
|
| 102 | + 'name' => _x( 'Vocabulary', 'post type general name', 'wordlift' ), |
|
| 103 | + 'singular_name' => _x( 'Entity', 'post type singular name', 'wordlift' ), |
|
| 104 | + 'add_new' => _x( 'Add New Entity', 'entity', 'wordlift' ), |
|
| 105 | + 'add_new_item' => __( 'Add New Entity', 'wordlift' ), |
|
| 106 | + 'edit_item' => __( 'Edit Entity', 'wordlift' ), |
|
| 107 | + 'new_item' => __( 'New Entity', 'wordlift' ), |
|
| 108 | + 'all_items' => __( 'All Entities', 'wordlift' ), |
|
| 109 | + 'view_item' => __( 'View Entity', 'wordlift' ), |
|
| 110 | + 'search_items' => __( 'Search in Vocabulary', 'wordlift' ), |
|
| 111 | + 'not_found' => __( 'No entities found', 'wordlift' ), |
|
| 112 | + 'not_found_in_trash' => __( 'No entities found in the Trash', 'wordlift' ), |
|
| 113 | + 'parent_item_colon' => '', |
|
| 114 | + 'menu_name' => __( 'Vocabulary', 'wordlift' ) |
|
| 115 | + ); |
|
| 116 | + |
|
| 117 | + $args = array( |
|
| 118 | + 'labels' => $labels, |
|
| 119 | + 'description' => 'Holds our vocabulary (set of entities) and entity specific data', |
|
| 120 | + 'public' => true, |
|
| 121 | + 'menu_position' => 20, |
|
| 122 | + // after the pages menu. |
|
| 123 | + 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ), |
|
| 124 | + 'has_archive' => true, |
|
| 125 | + 'menu_icon' => WP_CONTENT_URL . '/plugins/wordlift/images/svg/wl-vocabulary-icon.svg', |
|
| 126 | + // Although we define our slug here, we further manage linking to entities using the Wordlift_Entity_Link_Service. |
|
| 127 | + 'rewrite' => array( 'slug' => $this->slug ) |
|
| 128 | + ); |
|
| 129 | + |
|
| 130 | + register_post_type( $this->post_type, $args ); |
|
| 131 | + |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | 134 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * @param string $post_type The post type, e.g. entity. |
| 42 | 42 | * @param string $slug The entity type slug, if the slug is empty, the default slug will be used. |
| 43 | 43 | */ |
| 44 | - public function __construct( $post_type, $slug ) { |
|
| 44 | + public function __construct($post_type, $slug) { |
|
| 45 | 45 | |
| 46 | 46 | |
| 47 | 47 | $this->post_type = $post_type; |
@@ -99,19 +99,19 @@ discard block |
||
| 99 | 99 | public function register() { |
| 100 | 100 | |
| 101 | 101 | $labels = array( |
| 102 | - 'name' => _x( 'Vocabulary', 'post type general name', 'wordlift' ), |
|
| 103 | - 'singular_name' => _x( 'Entity', 'post type singular name', 'wordlift' ), |
|
| 104 | - 'add_new' => _x( 'Add New Entity', 'entity', 'wordlift' ), |
|
| 105 | - 'add_new_item' => __( 'Add New Entity', 'wordlift' ), |
|
| 106 | - 'edit_item' => __( 'Edit Entity', 'wordlift' ), |
|
| 107 | - 'new_item' => __( 'New Entity', 'wordlift' ), |
|
| 108 | - 'all_items' => __( 'All Entities', 'wordlift' ), |
|
| 109 | - 'view_item' => __( 'View Entity', 'wordlift' ), |
|
| 110 | - 'search_items' => __( 'Search in Vocabulary', 'wordlift' ), |
|
| 111 | - 'not_found' => __( 'No entities found', 'wordlift' ), |
|
| 112 | - 'not_found_in_trash' => __( 'No entities found in the Trash', 'wordlift' ), |
|
| 102 | + 'name' => _x('Vocabulary', 'post type general name', 'wordlift'), |
|
| 103 | + 'singular_name' => _x('Entity', 'post type singular name', 'wordlift'), |
|
| 104 | + 'add_new' => _x('Add New Entity', 'entity', 'wordlift'), |
|
| 105 | + 'add_new_item' => __('Add New Entity', 'wordlift'), |
|
| 106 | + 'edit_item' => __('Edit Entity', 'wordlift'), |
|
| 107 | + 'new_item' => __('New Entity', 'wordlift'), |
|
| 108 | + 'all_items' => __('All Entities', 'wordlift'), |
|
| 109 | + 'view_item' => __('View Entity', 'wordlift'), |
|
| 110 | + 'search_items' => __('Search in Vocabulary', 'wordlift'), |
|
| 111 | + 'not_found' => __('No entities found', 'wordlift'), |
|
| 112 | + 'not_found_in_trash' => __('No entities found in the Trash', 'wordlift'), |
|
| 113 | 113 | 'parent_item_colon' => '', |
| 114 | - 'menu_name' => __( 'Vocabulary', 'wordlift' ) |
|
| 114 | + 'menu_name' => __('Vocabulary', 'wordlift') |
|
| 115 | 115 | ); |
| 116 | 116 | |
| 117 | 117 | $args = array( |
@@ -120,14 +120,14 @@ discard block |
||
| 120 | 120 | 'public' => true, |
| 121 | 121 | 'menu_position' => 20, |
| 122 | 122 | // after the pages menu. |
| 123 | - 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ), |
|
| 123 | + 'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'comments'), |
|
| 124 | 124 | 'has_archive' => true, |
| 125 | - 'menu_icon' => WP_CONTENT_URL . '/plugins/wordlift/images/svg/wl-vocabulary-icon.svg', |
|
| 125 | + 'menu_icon' => WP_CONTENT_URL.'/plugins/wordlift/images/svg/wl-vocabulary-icon.svg', |
|
| 126 | 126 | // Although we define our slug here, we further manage linking to entities using the Wordlift_Entity_Link_Service. |
| 127 | - 'rewrite' => array( 'slug' => $this->slug ) |
|
| 127 | + 'rewrite' => array('slug' => $this->slug) |
|
| 128 | 128 | ); |
| 129 | 129 | |
| 130 | - register_post_type( $this->post_type, $args ); |
|
| 130 | + register_post_type($this->post_type, $args); |
|
| 131 | 131 | |
| 132 | 132 | } |
| 133 | 133 | |
@@ -29,547 +29,547 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class Wordlift { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * The loader that's responsible for maintaining and registering all hooks that power |
|
| 34 | - * the plugin. |
|
| 35 | - * |
|
| 36 | - * @since 1.0.0 |
|
| 37 | - * @access protected |
|
| 38 | - * @var Wordlift_Loader $loader Maintains and registers all hooks for the plugin. |
|
| 39 | - */ |
|
| 40 | - protected $loader; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * The unique identifier of this plugin. |
|
| 44 | - * |
|
| 45 | - * @since 1.0.0 |
|
| 46 | - * @access protected |
|
| 47 | - * @var string $plugin_name The string used to uniquely identify this plugin. |
|
| 48 | - */ |
|
| 49 | - protected $plugin_name; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * The current version of the plugin. |
|
| 53 | - * |
|
| 54 | - * @since 1.0.0 |
|
| 55 | - * @access protected |
|
| 56 | - * @var string $version The current version of the plugin. |
|
| 57 | - */ |
|
| 58 | - protected $version; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * The Thumbnail service. |
|
| 62 | - * |
|
| 63 | - * @since 3.1.5 |
|
| 64 | - * @access private |
|
| 65 | - * @var \Wordlift_Thumbnail_Service $thumbnail_service The Thumbnail service. |
|
| 66 | - */ |
|
| 67 | - private $thumbnail_service; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * The UI service. |
|
| 71 | - * |
|
| 72 | - * @since 3.2.0 |
|
| 73 | - * @access private |
|
| 74 | - * @var \Wordlift_UI_Service $ui_service The UI service. |
|
| 75 | - */ |
|
| 76 | - private $ui_service; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * The Schema service. |
|
| 80 | - * |
|
| 81 | - * @since 3.3.0 |
|
| 82 | - * @access private |
|
| 83 | - * @var \Wordlift_Schema_Service $schema_service The Schema service. |
|
| 84 | - */ |
|
| 85 | - private $schema_service; |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * The Entity service. |
|
| 89 | - * |
|
| 90 | - * @since 3.1.0 |
|
| 91 | - * @access private |
|
| 92 | - * @var \Wordlift_Entity_Service $entity_service The Entity service. |
|
| 93 | - */ |
|
| 94 | - private $entity_service; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * The Topic Taxonomy service. |
|
| 98 | - * |
|
| 99 | - * @since 3.5.0 |
|
| 100 | - * @access private |
|
| 101 | - * @var \Wordlift_Topic_Taxonomy_Service The Topic Taxonomy service. |
|
| 102 | - */ |
|
| 103 | - private $topic_taxonomy_service; |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * The User service. |
|
| 107 | - * |
|
| 108 | - * @since 3.1.7 |
|
| 109 | - * @access private |
|
| 110 | - * @var \Wordlift_User_Service $user_service The User service. |
|
| 111 | - */ |
|
| 112 | - private $user_service; |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * The Timeline service. |
|
| 116 | - * |
|
| 117 | - * @since 3.1.0 |
|
| 118 | - * @access private |
|
| 119 | - * @var \Wordlift_Timeline_Service $timeline_service The Timeline service. |
|
| 120 | - */ |
|
| 121 | - private $timeline_service; |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * The Redirect service. |
|
| 125 | - * |
|
| 126 | - * @since 3.2.0 |
|
| 127 | - * @access private |
|
| 128 | - * @var \Wordlift_Redirect_Service $redirect_service The Redirect service. |
|
| 129 | - */ |
|
| 130 | - private $redirect_service; |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * The Notice service. |
|
| 134 | - * |
|
| 135 | - * @since 3.3.0 |
|
| 136 | - * @access private |
|
| 137 | - * @var \Wordlift_Notice_Service $notice_service The Notice service. |
|
| 138 | - */ |
|
| 139 | - private $notice_service; |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * The Entity list customization. |
|
| 143 | - * |
|
| 144 | - * @since 3.3.0 |
|
| 145 | - * @access private |
|
| 146 | - * @var \Wordlift_List_Service $entity_list_service The Entity list service. |
|
| 147 | - */ |
|
| 148 | - private $entity_list_service; |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * The Entity Types Taxonomy Walker. |
|
| 152 | - * |
|
| 153 | - * @since 3.1.0 |
|
| 154 | - * @access private |
|
| 155 | - * @var \Wordlift_Entity_Types_Taxonomy_Walker $entity_types_taxonomy_walker The Entity Types Taxonomy Walker |
|
| 156 | - */ |
|
| 157 | - private $entity_types_taxonomy_walker; |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * The ShareThis service. |
|
| 161 | - * |
|
| 162 | - * @since 3.2.0 |
|
| 163 | - * @access private |
|
| 164 | - * @var \Wordlift_ShareThis_Service $sharethis_service The ShareThis service. |
|
| 165 | - */ |
|
| 166 | - private $sharethis_service; |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * The PrimaShop adapter. |
|
| 170 | - * |
|
| 171 | - * @since 3.2.3 |
|
| 172 | - * @access private |
|
| 173 | - * @var \Wordlift_PrimaShop_Adapter $primashop_adapter The PrimaShop adapter. |
|
| 174 | - */ |
|
| 175 | - private $primashop_adapter; |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * The WordLift Dashboard adapter. |
|
| 179 | - * |
|
| 180 | - * @since 3.4.0 |
|
| 181 | - * @access private |
|
| 182 | - * @var \Wordlift_Dashboard_Service $dashboard_service The WordLift Dashboard service; |
|
| 183 | - */ |
|
| 184 | - private $dashboard_service; |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * The entity type service. |
|
| 188 | - * |
|
| 189 | - * @since 3.6.0 |
|
| 190 | - * @access private |
|
| 191 | - * @var \Wordlift_Entity_Type_Service |
|
| 192 | - */ |
|
| 193 | - private $entity_type_service; |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * The entity link service used to mangle links to entities with a custom slug or even w/o a slug. |
|
| 197 | - * |
|
| 198 | - * @since 3.6.0 |
|
| 199 | - * @access private |
|
| 200 | - * @var \Wordlift_Entity_Link_Service |
|
| 201 | - */ |
|
| 202 | - private $entity_link_service; |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Define the core functionality of the plugin. |
|
| 206 | - * |
|
| 207 | - * Set the plugin name and the plugin version that can be used throughout the plugin. |
|
| 208 | - * Load the dependencies, define the locale, and set the hooks for the admin area and |
|
| 209 | - * the public-facing side of the site. |
|
| 210 | - * |
|
| 211 | - * @since 1.0.0 |
|
| 212 | - */ |
|
| 213 | - public function __construct() { |
|
| 214 | - |
|
| 215 | - $this->plugin_name = 'wordlift'; |
|
| 216 | - $this->version = '3.6.0-dev'; |
|
| 217 | - $this->load_dependencies(); |
|
| 218 | - $this->set_locale(); |
|
| 219 | - $this->define_admin_hooks(); |
|
| 220 | - $this->define_public_hooks(); |
|
| 221 | - |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * Load the required dependencies for this plugin. |
|
| 226 | - * |
|
| 227 | - * Include the following files that make up the plugin: |
|
| 228 | - * |
|
| 229 | - * - Wordlift_Loader. Orchestrates the hooks of the plugin. |
|
| 230 | - * - Wordlift_i18n. Defines internationalization functionality. |
|
| 231 | - * - Wordlift_Admin. Defines all hooks for the admin area. |
|
| 232 | - * - Wordlift_Public. Defines all hooks for the public side of the site. |
|
| 233 | - * |
|
| 234 | - * Create an instance of the loader which will be used to register the hooks |
|
| 235 | - * with WordPress. |
|
| 236 | - * |
|
| 237 | - * @since 1.0.0 |
|
| 238 | - * @access private |
|
| 239 | - */ |
|
| 240 | - private function load_dependencies() { |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * The class responsible for orchestrating the actions and filters of the |
|
| 244 | - * core plugin. |
|
| 245 | - */ |
|
| 246 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-loader.php'; |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * The class responsible for defining internationalization functionality |
|
| 250 | - * of the plugin. |
|
| 251 | - */ |
|
| 252 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-i18n.php'; |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * The Redirect service. |
|
| 256 | - */ |
|
| 257 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-redirect-service.php'; |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * The Log service. |
|
| 261 | - */ |
|
| 262 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-log-service.php'; |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * The entity post type service. |
|
| 266 | - */ |
|
| 267 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-type-service.php'; |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * The entity link service. |
|
| 271 | - */ |
|
| 272 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-link-service.php'; |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * The Query builder. |
|
| 276 | - */ |
|
| 277 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-query-builder.php'; |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * The Schema service. |
|
| 281 | - */ |
|
| 282 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-schema-service.php'; |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * The UI service. |
|
| 286 | - */ |
|
| 287 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-ui-service.php'; |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * The Thumbnail service. |
|
| 291 | - */ |
|
| 292 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-thumbnail-service.php'; |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * The Entity Types Taxonomy service. |
|
| 296 | - */ |
|
| 297 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-types-taxonomy-service.php'; |
|
| 298 | - |
|
| 299 | - /** |
|
| 300 | - * The Entity service. |
|
| 301 | - */ |
|
| 302 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-service.php'; |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * The User service. |
|
| 306 | - */ |
|
| 307 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-user-service.php'; |
|
| 308 | - |
|
| 309 | - /** |
|
| 310 | - * The Timeline service. |
|
| 311 | - */ |
|
| 312 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-timeline-service.php'; |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * The Topic Taxonomy service. |
|
| 316 | - */ |
|
| 317 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-topic-taxonomy-service.php'; |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * The class responsible for defining all actions that occur in the admin area. |
|
| 321 | - */ |
|
| 322 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin.php'; |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * The class to customize the entity list admin page. |
|
| 326 | - */ |
|
| 327 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-entity-list.php'; |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * The Entity Types Taxonomy Walker (transforms checkboxes into radios). |
|
| 331 | - */ |
|
| 332 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-entity-types-taxonomy-walker.php'; |
|
| 333 | - |
|
| 334 | - /** |
|
| 335 | - * The Notice service. |
|
| 336 | - */ |
|
| 337 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-notice-service.php'; |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * The PrimaShop adapter. |
|
| 341 | - */ |
|
| 342 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-primashop-adapter.php'; |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * The WordLift Dashboard service. |
|
| 346 | - */ |
|
| 347 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard.php'; |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * The class responsible for defining all actions that occur in the public-facing |
|
| 351 | - * side of the site. |
|
| 352 | - */ |
|
| 353 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-public.php'; |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * The Timeline shortcode. |
|
| 357 | - */ |
|
| 358 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-timeline-shortcode.php'; |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * The ShareThis service. |
|
| 362 | - */ |
|
| 363 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-sharethis-service.php'; |
|
| 32 | + /** |
|
| 33 | + * The loader that's responsible for maintaining and registering all hooks that power |
|
| 34 | + * the plugin. |
|
| 35 | + * |
|
| 36 | + * @since 1.0.0 |
|
| 37 | + * @access protected |
|
| 38 | + * @var Wordlift_Loader $loader Maintains and registers all hooks for the plugin. |
|
| 39 | + */ |
|
| 40 | + protected $loader; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * The unique identifier of this plugin. |
|
| 44 | + * |
|
| 45 | + * @since 1.0.0 |
|
| 46 | + * @access protected |
|
| 47 | + * @var string $plugin_name The string used to uniquely identify this plugin. |
|
| 48 | + */ |
|
| 49 | + protected $plugin_name; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * The current version of the plugin. |
|
| 53 | + * |
|
| 54 | + * @since 1.0.0 |
|
| 55 | + * @access protected |
|
| 56 | + * @var string $version The current version of the plugin. |
|
| 57 | + */ |
|
| 58 | + protected $version; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * The Thumbnail service. |
|
| 62 | + * |
|
| 63 | + * @since 3.1.5 |
|
| 64 | + * @access private |
|
| 65 | + * @var \Wordlift_Thumbnail_Service $thumbnail_service The Thumbnail service. |
|
| 66 | + */ |
|
| 67 | + private $thumbnail_service; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * The UI service. |
|
| 71 | + * |
|
| 72 | + * @since 3.2.0 |
|
| 73 | + * @access private |
|
| 74 | + * @var \Wordlift_UI_Service $ui_service The UI service. |
|
| 75 | + */ |
|
| 76 | + private $ui_service; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * The Schema service. |
|
| 80 | + * |
|
| 81 | + * @since 3.3.0 |
|
| 82 | + * @access private |
|
| 83 | + * @var \Wordlift_Schema_Service $schema_service The Schema service. |
|
| 84 | + */ |
|
| 85 | + private $schema_service; |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * The Entity service. |
|
| 89 | + * |
|
| 90 | + * @since 3.1.0 |
|
| 91 | + * @access private |
|
| 92 | + * @var \Wordlift_Entity_Service $entity_service The Entity service. |
|
| 93 | + */ |
|
| 94 | + private $entity_service; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * The Topic Taxonomy service. |
|
| 98 | + * |
|
| 99 | + * @since 3.5.0 |
|
| 100 | + * @access private |
|
| 101 | + * @var \Wordlift_Topic_Taxonomy_Service The Topic Taxonomy service. |
|
| 102 | + */ |
|
| 103 | + private $topic_taxonomy_service; |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * The User service. |
|
| 107 | + * |
|
| 108 | + * @since 3.1.7 |
|
| 109 | + * @access private |
|
| 110 | + * @var \Wordlift_User_Service $user_service The User service. |
|
| 111 | + */ |
|
| 112 | + private $user_service; |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * The Timeline service. |
|
| 116 | + * |
|
| 117 | + * @since 3.1.0 |
|
| 118 | + * @access private |
|
| 119 | + * @var \Wordlift_Timeline_Service $timeline_service The Timeline service. |
|
| 120 | + */ |
|
| 121 | + private $timeline_service; |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * The Redirect service. |
|
| 125 | + * |
|
| 126 | + * @since 3.2.0 |
|
| 127 | + * @access private |
|
| 128 | + * @var \Wordlift_Redirect_Service $redirect_service The Redirect service. |
|
| 129 | + */ |
|
| 130 | + private $redirect_service; |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * The Notice service. |
|
| 134 | + * |
|
| 135 | + * @since 3.3.0 |
|
| 136 | + * @access private |
|
| 137 | + * @var \Wordlift_Notice_Service $notice_service The Notice service. |
|
| 138 | + */ |
|
| 139 | + private $notice_service; |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * The Entity list customization. |
|
| 143 | + * |
|
| 144 | + * @since 3.3.0 |
|
| 145 | + * @access private |
|
| 146 | + * @var \Wordlift_List_Service $entity_list_service The Entity list service. |
|
| 147 | + */ |
|
| 148 | + private $entity_list_service; |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * The Entity Types Taxonomy Walker. |
|
| 152 | + * |
|
| 153 | + * @since 3.1.0 |
|
| 154 | + * @access private |
|
| 155 | + * @var \Wordlift_Entity_Types_Taxonomy_Walker $entity_types_taxonomy_walker The Entity Types Taxonomy Walker |
|
| 156 | + */ |
|
| 157 | + private $entity_types_taxonomy_walker; |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * The ShareThis service. |
|
| 161 | + * |
|
| 162 | + * @since 3.2.0 |
|
| 163 | + * @access private |
|
| 164 | + * @var \Wordlift_ShareThis_Service $sharethis_service The ShareThis service. |
|
| 165 | + */ |
|
| 166 | + private $sharethis_service; |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * The PrimaShop adapter. |
|
| 170 | + * |
|
| 171 | + * @since 3.2.3 |
|
| 172 | + * @access private |
|
| 173 | + * @var \Wordlift_PrimaShop_Adapter $primashop_adapter The PrimaShop adapter. |
|
| 174 | + */ |
|
| 175 | + private $primashop_adapter; |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * The WordLift Dashboard adapter. |
|
| 179 | + * |
|
| 180 | + * @since 3.4.0 |
|
| 181 | + * @access private |
|
| 182 | + * @var \Wordlift_Dashboard_Service $dashboard_service The WordLift Dashboard service; |
|
| 183 | + */ |
|
| 184 | + private $dashboard_service; |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * The entity type service. |
|
| 188 | + * |
|
| 189 | + * @since 3.6.0 |
|
| 190 | + * @access private |
|
| 191 | + * @var \Wordlift_Entity_Type_Service |
|
| 192 | + */ |
|
| 193 | + private $entity_type_service; |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * The entity link service used to mangle links to entities with a custom slug or even w/o a slug. |
|
| 197 | + * |
|
| 198 | + * @since 3.6.0 |
|
| 199 | + * @access private |
|
| 200 | + * @var \Wordlift_Entity_Link_Service |
|
| 201 | + */ |
|
| 202 | + private $entity_link_service; |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Define the core functionality of the plugin. |
|
| 206 | + * |
|
| 207 | + * Set the plugin name and the plugin version that can be used throughout the plugin. |
|
| 208 | + * Load the dependencies, define the locale, and set the hooks for the admin area and |
|
| 209 | + * the public-facing side of the site. |
|
| 210 | + * |
|
| 211 | + * @since 1.0.0 |
|
| 212 | + */ |
|
| 213 | + public function __construct() { |
|
| 214 | + |
|
| 215 | + $this->plugin_name = 'wordlift'; |
|
| 216 | + $this->version = '3.6.0-dev'; |
|
| 217 | + $this->load_dependencies(); |
|
| 218 | + $this->set_locale(); |
|
| 219 | + $this->define_admin_hooks(); |
|
| 220 | + $this->define_public_hooks(); |
|
| 221 | + |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * Load the required dependencies for this plugin. |
|
| 226 | + * |
|
| 227 | + * Include the following files that make up the plugin: |
|
| 228 | + * |
|
| 229 | + * - Wordlift_Loader. Orchestrates the hooks of the plugin. |
|
| 230 | + * - Wordlift_i18n. Defines internationalization functionality. |
|
| 231 | + * - Wordlift_Admin. Defines all hooks for the admin area. |
|
| 232 | + * - Wordlift_Public. Defines all hooks for the public side of the site. |
|
| 233 | + * |
|
| 234 | + * Create an instance of the loader which will be used to register the hooks |
|
| 235 | + * with WordPress. |
|
| 236 | + * |
|
| 237 | + * @since 1.0.0 |
|
| 238 | + * @access private |
|
| 239 | + */ |
|
| 240 | + private function load_dependencies() { |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * The class responsible for orchestrating the actions and filters of the |
|
| 244 | + * core plugin. |
|
| 245 | + */ |
|
| 246 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-loader.php'; |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * The class responsible for defining internationalization functionality |
|
| 250 | + * of the plugin. |
|
| 251 | + */ |
|
| 252 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-i18n.php'; |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * The Redirect service. |
|
| 256 | + */ |
|
| 257 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-redirect-service.php'; |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * The Log service. |
|
| 261 | + */ |
|
| 262 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-log-service.php'; |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * The entity post type service. |
|
| 266 | + */ |
|
| 267 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-type-service.php'; |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * The entity link service. |
|
| 271 | + */ |
|
| 272 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-link-service.php'; |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * The Query builder. |
|
| 276 | + */ |
|
| 277 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-query-builder.php'; |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * The Schema service. |
|
| 281 | + */ |
|
| 282 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-schema-service.php'; |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * The UI service. |
|
| 286 | + */ |
|
| 287 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-ui-service.php'; |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * The Thumbnail service. |
|
| 291 | + */ |
|
| 292 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-thumbnail-service.php'; |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * The Entity Types Taxonomy service. |
|
| 296 | + */ |
|
| 297 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-types-taxonomy-service.php'; |
|
| 298 | + |
|
| 299 | + /** |
|
| 300 | + * The Entity service. |
|
| 301 | + */ |
|
| 302 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-service.php'; |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * The User service. |
|
| 306 | + */ |
|
| 307 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-user-service.php'; |
|
| 308 | + |
|
| 309 | + /** |
|
| 310 | + * The Timeline service. |
|
| 311 | + */ |
|
| 312 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-timeline-service.php'; |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * The Topic Taxonomy service. |
|
| 316 | + */ |
|
| 317 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-topic-taxonomy-service.php'; |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * The class responsible for defining all actions that occur in the admin area. |
|
| 321 | + */ |
|
| 322 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin.php'; |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * The class to customize the entity list admin page. |
|
| 326 | + */ |
|
| 327 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-entity-list.php'; |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * The Entity Types Taxonomy Walker (transforms checkboxes into radios). |
|
| 331 | + */ |
|
| 332 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-entity-types-taxonomy-walker.php'; |
|
| 333 | + |
|
| 334 | + /** |
|
| 335 | + * The Notice service. |
|
| 336 | + */ |
|
| 337 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-notice-service.php'; |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * The PrimaShop adapter. |
|
| 341 | + */ |
|
| 342 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-primashop-adapter.php'; |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * The WordLift Dashboard service. |
|
| 346 | + */ |
|
| 347 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard.php'; |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * The class responsible for defining all actions that occur in the public-facing |
|
| 351 | + * side of the site. |
|
| 352 | + */ |
|
| 353 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-public.php'; |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * The Timeline shortcode. |
|
| 357 | + */ |
|
| 358 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-timeline-shortcode.php'; |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * The ShareThis service. |
|
| 362 | + */ |
|
| 363 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-sharethis-service.php'; |
|
| 364 | 364 | |
| 365 | - $this->loader = new Wordlift_Loader(); |
|
| 365 | + $this->loader = new Wordlift_Loader(); |
|
| 366 | 366 | |
| 367 | - // Instantiate a global logger. |
|
| 368 | - global $wl_logger; |
|
| 369 | - $wl_logger = Wordlift_Log_Service::get_logger( 'WordLift' ); |
|
| 367 | + // Instantiate a global logger. |
|
| 368 | + global $wl_logger; |
|
| 369 | + $wl_logger = Wordlift_Log_Service::get_logger( 'WordLift' ); |
|
| 370 | 370 | |
| 371 | - // Create an entity type service instance. It'll be later bound to the init action. |
|
| 372 | - $this->entity_type_service = new Wordlift_Entity_Type_Service( Wordlift_Entity_Service::TYPE_NAME, WL_ENTITY_TYPE_SLUG ); |
|
| 371 | + // Create an entity type service instance. It'll be later bound to the init action. |
|
| 372 | + $this->entity_type_service = new Wordlift_Entity_Type_Service( Wordlift_Entity_Service::TYPE_NAME, WL_ENTITY_TYPE_SLUG ); |
|
| 373 | 373 | |
| 374 | - // Create an entity link service instance. It'll be later bound to the post_type_link and pre_get_posts actions. |
|
| 375 | - $this->entity_link_service = new Wordlift_Entity_Link_Service( $this->entity_type_service, WL_ENTITY_TYPE_SLUG ); |
|
| 374 | + // Create an entity link service instance. It'll be later bound to the post_type_link and pre_get_posts actions. |
|
| 375 | + $this->entity_link_service = new Wordlift_Entity_Link_Service( $this->entity_type_service, WL_ENTITY_TYPE_SLUG ); |
|
| 376 | 376 | |
| 377 | - // Create an instance of the UI service. |
|
| 378 | - $this->ui_service = new Wordlift_UI_Service(); |
|
| 377 | + // Create an instance of the UI service. |
|
| 378 | + $this->ui_service = new Wordlift_UI_Service(); |
|
| 379 | 379 | |
| 380 | - // Create an instance of the Thumbnail service. Later it'll be hooked to post meta events. |
|
| 381 | - $this->thumbnail_service = new Wordlift_Thumbnail_Service(); |
|
| 380 | + // Create an instance of the Thumbnail service. Later it'll be hooked to post meta events. |
|
| 381 | + $this->thumbnail_service = new Wordlift_Thumbnail_Service(); |
|
| 382 | 382 | |
| 383 | - // Create an instance of the Schema service. |
|
| 384 | - $this->schema_service = new Wordlift_Schema_Service(); |
|
| 383 | + // Create an instance of the Schema service. |
|
| 384 | + $this->schema_service = new Wordlift_Schema_Service(); |
|
| 385 | 385 | |
| 386 | - // Create an instance of the Notice service. |
|
| 387 | - $this->notice_service = new Wordlift_Notice_Service(); |
|
| 386 | + // Create an instance of the Notice service. |
|
| 387 | + $this->notice_service = new Wordlift_Notice_Service(); |
|
| 388 | 388 | |
| 389 | - // Create an instance of the Entity service, passing the UI service to draw parts of the Entity admin page. |
|
| 390 | - $this->entity_service = new Wordlift_Entity_Service( $this->ui_service, $this->schema_service, $this->notice_service ); |
|
| 389 | + // Create an instance of the Entity service, passing the UI service to draw parts of the Entity admin page. |
|
| 390 | + $this->entity_service = new Wordlift_Entity_Service( $this->ui_service, $this->schema_service, $this->notice_service ); |
|
| 391 | 391 | |
| 392 | - // Create an instance of the User service. |
|
| 393 | - $this->user_service = new Wordlift_User_Service(); |
|
| 394 | - |
|
| 395 | - // Create a new instance of the Timeline service and Timeline shortcode. |
|
| 396 | - $this->timeline_service = new Wordlift_Timeline_Service( $this->entity_service ); |
|
| 392 | + // Create an instance of the User service. |
|
| 393 | + $this->user_service = new Wordlift_User_Service(); |
|
| 394 | + |
|
| 395 | + // Create a new instance of the Timeline service and Timeline shortcode. |
|
| 396 | + $this->timeline_service = new Wordlift_Timeline_Service( $this->entity_service ); |
|
| 397 | 397 | |
| 398 | - // Create a new instance of the Redirect service. |
|
| 399 | - $this->redirect_service = new Wordlift_Redirect_Service( $this->entity_service ); |
|
| 398 | + // Create a new instance of the Redirect service. |
|
| 399 | + $this->redirect_service = new Wordlift_Redirect_Service( $this->entity_service ); |
|
| 400 | 400 | |
| 401 | - // Create a new instance of the Redirect service. |
|
| 402 | - $this->dashboard_service = new Wordlift_Dashboard_Service( $this->entity_service ); |
|
| 401 | + // Create a new instance of the Redirect service. |
|
| 402 | + $this->dashboard_service = new Wordlift_Dashboard_Service( $this->entity_service ); |
|
| 403 | 403 | |
| 404 | - // Create an instance of the Timeline shortcode. |
|
| 405 | - new Wordlift_Timeline_Shortcode(); |
|
| 404 | + // Create an instance of the Timeline shortcode. |
|
| 405 | + new Wordlift_Timeline_Shortcode(); |
|
| 406 | 406 | |
| 407 | - // Create entity list customization (wp-admin/edit.php) |
|
| 408 | - $this->entity_list_service = new Wordlift_Entity_List_Service( $this->entity_service ); |
|
| 409 | - |
|
| 410 | - $this->entity_types_taxonomy_walker = new Wordlift_Entity_Types_Taxonomy_Walker(); |
|
| 407 | + // Create entity list customization (wp-admin/edit.php) |
|
| 408 | + $this->entity_list_service = new Wordlift_Entity_List_Service( $this->entity_service ); |
|
| 409 | + |
|
| 410 | + $this->entity_types_taxonomy_walker = new Wordlift_Entity_Types_Taxonomy_Walker(); |
|
| 411 | 411 | |
| 412 | - $this->topic_taxonomy_service = new Wordlift_Topic_Taxonomy_Service(); |
|
| 412 | + $this->topic_taxonomy_service = new Wordlift_Topic_Taxonomy_Service(); |
|
| 413 | 413 | |
| 414 | - // Create an instance of the ShareThis service, later we hook it to the_content and the_excerpt filters. |
|
| 415 | - $this->sharethis_service = new Wordlift_ShareThis_Service(); |
|
| 414 | + // Create an instance of the ShareThis service, later we hook it to the_content and the_excerpt filters. |
|
| 415 | + $this->sharethis_service = new Wordlift_ShareThis_Service(); |
|
| 416 | 416 | |
| 417 | - // Create an instance of the PrimaShop adapter. |
|
| 418 | - $this->primashop_adapter = new Wordlift_PrimaShop_Adapter(); |
|
| 419 | - } |
|
| 417 | + // Create an instance of the PrimaShop adapter. |
|
| 418 | + $this->primashop_adapter = new Wordlift_PrimaShop_Adapter(); |
|
| 419 | + } |
|
| 420 | 420 | |
| 421 | - /** |
|
| 422 | - * Define the locale for this plugin for internationalization. |
|
| 423 | - * |
|
| 424 | - * Uses the Wordlift_i18n class in order to set the domain and to register the hook |
|
| 425 | - * with WordPress. |
|
| 426 | - * |
|
| 427 | - * @since 1.0.0 |
|
| 428 | - * @access private |
|
| 429 | - */ |
|
| 430 | - private function set_locale() { |
|
| 421 | + /** |
|
| 422 | + * Define the locale for this plugin for internationalization. |
|
| 423 | + * |
|
| 424 | + * Uses the Wordlift_i18n class in order to set the domain and to register the hook |
|
| 425 | + * with WordPress. |
|
| 426 | + * |
|
| 427 | + * @since 1.0.0 |
|
| 428 | + * @access private |
|
| 429 | + */ |
|
| 430 | + private function set_locale() { |
|
| 431 | 431 | |
| 432 | - $plugin_i18n = new Wordlift_i18n(); |
|
| 433 | - $plugin_i18n->set_domain( $this->get_plugin_name() ); |
|
| 432 | + $plugin_i18n = new Wordlift_i18n(); |
|
| 433 | + $plugin_i18n->set_domain( $this->get_plugin_name() ); |
|
| 434 | 434 | |
| 435 | - $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); |
|
| 435 | + $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); |
|
| 436 | 436 | |
| 437 | - } |
|
| 437 | + } |
|
| 438 | 438 | |
| 439 | - /** |
|
| 440 | - * Register all of the hooks related to the admin area functionality |
|
| 441 | - * of the plugin. |
|
| 442 | - * |
|
| 443 | - * @since 1.0.0 |
|
| 444 | - * @access private |
|
| 445 | - */ |
|
| 446 | - private function define_admin_hooks() { |
|
| 439 | + /** |
|
| 440 | + * Register all of the hooks related to the admin area functionality |
|
| 441 | + * of the plugin. |
|
| 442 | + * |
|
| 443 | + * @since 1.0.0 |
|
| 444 | + * @access private |
|
| 445 | + */ |
|
| 446 | + private function define_admin_hooks() { |
|
| 447 | 447 | |
| 448 | - $plugin_admin = new Wordlift_Admin( $this->get_plugin_name(), $this->get_version() ); |
|
| 448 | + $plugin_admin = new Wordlift_Admin( $this->get_plugin_name(), $this->get_version() ); |
|
| 449 | 449 | |
| 450 | - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); |
|
| 451 | - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); |
|
| 450 | + $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); |
|
| 451 | + $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); |
|
| 452 | 452 | |
| 453 | - // Hook the init action to the Topic Taxonomy service. |
|
| 454 | - $this->loader->add_action( 'init', $this->topic_taxonomy_service, 'init', 0 ); |
|
| 453 | + // Hook the init action to the Topic Taxonomy service. |
|
| 454 | + $this->loader->add_action( 'init', $this->topic_taxonomy_service, 'init', 0 ); |
|
| 455 | 455 | |
| 456 | - // Hook the deleted_post_meta action to the Thumbnail service. |
|
| 457 | - $this->loader->add_action( 'deleted_post_meta', $this->thumbnail_service, 'deleted_post_meta', 10, 4 ); |
|
| 456 | + // Hook the deleted_post_meta action to the Thumbnail service. |
|
| 457 | + $this->loader->add_action( 'deleted_post_meta', $this->thumbnail_service, 'deleted_post_meta', 10, 4 ); |
|
| 458 | 458 | |
| 459 | - // Hook the added_post_meta action to the Thumbnail service. |
|
| 460 | - $this->loader->add_action( 'added_post_meta', $this->thumbnail_service, 'added_or_updated_post_meta', 10, 4 ); |
|
| 461 | - |
|
| 462 | - // Hook the updated_post_meta action to the Thumbnail service. |
|
| 463 | - $this->loader->add_action( 'updated_post_meta', $this->thumbnail_service, 'added_or_updated_post_meta', 10, 4 ); |
|
| 459 | + // Hook the added_post_meta action to the Thumbnail service. |
|
| 460 | + $this->loader->add_action( 'added_post_meta', $this->thumbnail_service, 'added_or_updated_post_meta', 10, 4 ); |
|
| 461 | + |
|
| 462 | + // Hook the updated_post_meta action to the Thumbnail service. |
|
| 463 | + $this->loader->add_action( 'updated_post_meta', $this->thumbnail_service, 'added_or_updated_post_meta', 10, 4 ); |
|
| 464 | 464 | |
| 465 | - // Hook posts inserts (or updates) to the user service. |
|
| 466 | - $this->loader->add_action( 'wp_insert_post', $this->user_service, 'wp_insert_post', 10, 3 ); |
|
| 467 | - |
|
| 468 | - // Hook the AJAX wl_timeline action to the Timeline service. |
|
| 469 | - $this->loader->add_action( 'wp_ajax_wl_timeline', $this->timeline_service, 'ajax_timeline' ); |
|
| 470 | - |
|
| 471 | - // Register custom allowed redirect hosts. |
|
| 472 | - $this->loader->add_filter( 'allowed_redirect_hosts', $this->redirect_service, 'allowed_redirect_hosts' ); |
|
| 473 | - // Hook the AJAX wordlift_redirect action to the Redirect service. |
|
| 474 | - $this->loader->add_action( 'wp_ajax_wordlift_redirect', $this->redirect_service, 'ajax_redirect' ); |
|
| 475 | - // Hook the AJAX wordlift_redirect action to the Redirect service. |
|
| 476 | - $this->loader->add_action( 'wp_ajax_wordlift_get_stats', $this->dashboard_service, 'ajax_get_stats' ); |
|
| 477 | - // Hook the AJAX wordlift_redirect action to the Redirect service. |
|
| 478 | - $this->loader->add_action( 'wp_dashboard_setup', $this->dashboard_service, 'add_dashboard_widgets' ); |
|
| 479 | - |
|
| 480 | - // Hook save_post to the entity service to update custom fields (such as alternate labels). |
|
| 481 | - // We have a priority of 9 because we want to be executed before data is sent to Redlink. |
|
| 482 | - $this->loader->add_action( 'save_post', $this->entity_service, 'save_post', 9, 3 ); |
|
| 483 | - $this->loader->add_action( 'save_post_entity', $this->entity_service, 'set_rating_for', 10, 1 ); |
|
| 484 | - |
|
| 485 | - $this->loader->add_action( 'edit_form_before_permalink', $this->entity_service, 'edit_form_before_permalink', 10, 1 ); |
|
| 486 | - $this->loader->add_action( 'in_admin_header', $this->entity_service, 'in_admin_header' ); |
|
| 487 | - |
|
| 488 | - // Entity listing customization (wp-admin/edit.php) |
|
| 489 | - // Add custom columns |
|
| 490 | - $this->loader->add_filter( 'manage_entity_posts_columns', $this->entity_list_service, 'register_custom_columns' ); |
|
| 491 | - $this->loader->add_filter( 'manage_entity_posts_custom_column', $this->entity_list_service, 'render_custom_columns', 10, 2 ); |
|
| 492 | - // Add 4W selection |
|
| 493 | - $this->loader->add_action( 'restrict_manage_posts', $this->entity_list_service, 'restrict_manage_posts_classification_scope' ); |
|
| 494 | - $this->loader->add_filter( 'posts_clauses', $this->entity_list_service, 'posts_clauses_classification_scope' ); |
|
| 495 | - |
|
| 496 | - $this->loader->add_filter( 'wp_terms_checklist_args', $this->entity_types_taxonomy_walker, 'terms_checklist_args' ); |
|
| 497 | - |
|
| 498 | - // Hook the PrimaShop adapter to <em>prima_metabox_entity_header_args</em> in order to add header support for |
|
| 499 | - // entities. |
|
| 500 | - $this->loader->add_filter( 'prima_metabox_entity_header_args', $this->primashop_adapter, 'prima_metabox_entity_header_args', 10, 2 ); |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - /** |
|
| 504 | - * Register all of the hooks related to the public-facing functionality |
|
| 505 | - * of the plugin. |
|
| 506 | - * |
|
| 507 | - * @since 1.0.0 |
|
| 508 | - * @access private |
|
| 509 | - */ |
|
| 510 | - private function define_public_hooks() { |
|
| 511 | - |
|
| 512 | - $plugin_public = new Wordlift_Public( $this->get_plugin_name(), $this->get_version() ); |
|
| 513 | - |
|
| 514 | - // Register the entity post type. |
|
| 515 | - $this->loader->add_action( 'init', $this->entity_type_service, 'register' ); |
|
| 516 | - |
|
| 517 | - // Bind the link generation and handling hooks to the entity link service. |
|
| 518 | - $this->loader->add_filter( 'post_type_link', $this->entity_link_service, 'post_type_link', 10, 4 ); |
|
| 519 | - $this->loader->add_action( 'pre_get_posts', $this->entity_link_service, 'pre_get_posts', 10, 1 ); |
|
| 520 | - $this->loader->add_filter( 'wp_unique_post_slug_is_bad_flat_slug', $this->entity_link_service, 'wp_unique_post_slug_is_bad_flat_slug', 10, 3 ); |
|
| 521 | - $this->loader->add_filter( 'wp_unique_post_slug_is_bad_hierarchical_slug', $this->entity_link_service, 'wp_unique_post_slug_is_bad_hierarchical_slug', 10, 4 ); |
|
| 522 | - |
|
| 523 | - $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); |
|
| 524 | - $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); |
|
| 525 | - |
|
| 526 | - // Hook the AJAX wl_timeline action to the Timeline service. |
|
| 527 | - $this->loader->add_action( 'wp_ajax_nopriv_wl_timeline', $this->timeline_service, 'ajax_timeline' ); |
|
| 528 | - |
|
| 529 | - // Hook the ShareThis service. |
|
| 530 | - $this->loader->add_filter( 'the_content', $this->sharethis_service, 'the_content', 99 ); |
|
| 531 | - $this->loader->add_filter( 'the_excerpt', $this->sharethis_service, 'the_excerpt', 99 ); |
|
| 532 | - |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - /** |
|
| 536 | - * Run the loader to execute all of the hooks with WordPress. |
|
| 537 | - * |
|
| 538 | - * @since 1.0.0 |
|
| 539 | - */ |
|
| 540 | - public function run() { |
|
| 541 | - $this->loader->run(); |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - /** |
|
| 545 | - * The name of the plugin used to uniquely identify it within the context of |
|
| 546 | - * WordPress and to define internationalization functionality. |
|
| 547 | - * |
|
| 548 | - * @since 1.0.0 |
|
| 549 | - * @return string The name of the plugin. |
|
| 550 | - */ |
|
| 551 | - public function get_plugin_name() { |
|
| 552 | - return $this->plugin_name; |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - /** |
|
| 556 | - * The reference to the class that orchestrates the hooks with the plugin. |
|
| 557 | - * |
|
| 558 | - * @since 1.0.0 |
|
| 559 | - * @return Wordlift_Loader Orchestrates the hooks of the plugin. |
|
| 560 | - */ |
|
| 561 | - public function get_loader() { |
|
| 562 | - return $this->loader; |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * Retrieve the version number of the plugin. |
|
| 567 | - * |
|
| 568 | - * @since 1.0.0 |
|
| 569 | - * @return string The version number of the plugin. |
|
| 570 | - */ |
|
| 571 | - public function get_version() { |
|
| 572 | - return $this->version; |
|
| 573 | - } |
|
| 465 | + // Hook posts inserts (or updates) to the user service. |
|
| 466 | + $this->loader->add_action( 'wp_insert_post', $this->user_service, 'wp_insert_post', 10, 3 ); |
|
| 467 | + |
|
| 468 | + // Hook the AJAX wl_timeline action to the Timeline service. |
|
| 469 | + $this->loader->add_action( 'wp_ajax_wl_timeline', $this->timeline_service, 'ajax_timeline' ); |
|
| 470 | + |
|
| 471 | + // Register custom allowed redirect hosts. |
|
| 472 | + $this->loader->add_filter( 'allowed_redirect_hosts', $this->redirect_service, 'allowed_redirect_hosts' ); |
|
| 473 | + // Hook the AJAX wordlift_redirect action to the Redirect service. |
|
| 474 | + $this->loader->add_action( 'wp_ajax_wordlift_redirect', $this->redirect_service, 'ajax_redirect' ); |
|
| 475 | + // Hook the AJAX wordlift_redirect action to the Redirect service. |
|
| 476 | + $this->loader->add_action( 'wp_ajax_wordlift_get_stats', $this->dashboard_service, 'ajax_get_stats' ); |
|
| 477 | + // Hook the AJAX wordlift_redirect action to the Redirect service. |
|
| 478 | + $this->loader->add_action( 'wp_dashboard_setup', $this->dashboard_service, 'add_dashboard_widgets' ); |
|
| 479 | + |
|
| 480 | + // Hook save_post to the entity service to update custom fields (such as alternate labels). |
|
| 481 | + // We have a priority of 9 because we want to be executed before data is sent to Redlink. |
|
| 482 | + $this->loader->add_action( 'save_post', $this->entity_service, 'save_post', 9, 3 ); |
|
| 483 | + $this->loader->add_action( 'save_post_entity', $this->entity_service, 'set_rating_for', 10, 1 ); |
|
| 484 | + |
|
| 485 | + $this->loader->add_action( 'edit_form_before_permalink', $this->entity_service, 'edit_form_before_permalink', 10, 1 ); |
|
| 486 | + $this->loader->add_action( 'in_admin_header', $this->entity_service, 'in_admin_header' ); |
|
| 487 | + |
|
| 488 | + // Entity listing customization (wp-admin/edit.php) |
|
| 489 | + // Add custom columns |
|
| 490 | + $this->loader->add_filter( 'manage_entity_posts_columns', $this->entity_list_service, 'register_custom_columns' ); |
|
| 491 | + $this->loader->add_filter( 'manage_entity_posts_custom_column', $this->entity_list_service, 'render_custom_columns', 10, 2 ); |
|
| 492 | + // Add 4W selection |
|
| 493 | + $this->loader->add_action( 'restrict_manage_posts', $this->entity_list_service, 'restrict_manage_posts_classification_scope' ); |
|
| 494 | + $this->loader->add_filter( 'posts_clauses', $this->entity_list_service, 'posts_clauses_classification_scope' ); |
|
| 495 | + |
|
| 496 | + $this->loader->add_filter( 'wp_terms_checklist_args', $this->entity_types_taxonomy_walker, 'terms_checklist_args' ); |
|
| 497 | + |
|
| 498 | + // Hook the PrimaShop adapter to <em>prima_metabox_entity_header_args</em> in order to add header support for |
|
| 499 | + // entities. |
|
| 500 | + $this->loader->add_filter( 'prima_metabox_entity_header_args', $this->primashop_adapter, 'prima_metabox_entity_header_args', 10, 2 ); |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + /** |
|
| 504 | + * Register all of the hooks related to the public-facing functionality |
|
| 505 | + * of the plugin. |
|
| 506 | + * |
|
| 507 | + * @since 1.0.0 |
|
| 508 | + * @access private |
|
| 509 | + */ |
|
| 510 | + private function define_public_hooks() { |
|
| 511 | + |
|
| 512 | + $plugin_public = new Wordlift_Public( $this->get_plugin_name(), $this->get_version() ); |
|
| 513 | + |
|
| 514 | + // Register the entity post type. |
|
| 515 | + $this->loader->add_action( 'init', $this->entity_type_service, 'register' ); |
|
| 516 | + |
|
| 517 | + // Bind the link generation and handling hooks to the entity link service. |
|
| 518 | + $this->loader->add_filter( 'post_type_link', $this->entity_link_service, 'post_type_link', 10, 4 ); |
|
| 519 | + $this->loader->add_action( 'pre_get_posts', $this->entity_link_service, 'pre_get_posts', 10, 1 ); |
|
| 520 | + $this->loader->add_filter( 'wp_unique_post_slug_is_bad_flat_slug', $this->entity_link_service, 'wp_unique_post_slug_is_bad_flat_slug', 10, 3 ); |
|
| 521 | + $this->loader->add_filter( 'wp_unique_post_slug_is_bad_hierarchical_slug', $this->entity_link_service, 'wp_unique_post_slug_is_bad_hierarchical_slug', 10, 4 ); |
|
| 522 | + |
|
| 523 | + $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); |
|
| 524 | + $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); |
|
| 525 | + |
|
| 526 | + // Hook the AJAX wl_timeline action to the Timeline service. |
|
| 527 | + $this->loader->add_action( 'wp_ajax_nopriv_wl_timeline', $this->timeline_service, 'ajax_timeline' ); |
|
| 528 | + |
|
| 529 | + // Hook the ShareThis service. |
|
| 530 | + $this->loader->add_filter( 'the_content', $this->sharethis_service, 'the_content', 99 ); |
|
| 531 | + $this->loader->add_filter( 'the_excerpt', $this->sharethis_service, 'the_excerpt', 99 ); |
|
| 532 | + |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + /** |
|
| 536 | + * Run the loader to execute all of the hooks with WordPress. |
|
| 537 | + * |
|
| 538 | + * @since 1.0.0 |
|
| 539 | + */ |
|
| 540 | + public function run() { |
|
| 541 | + $this->loader->run(); |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + /** |
|
| 545 | + * The name of the plugin used to uniquely identify it within the context of |
|
| 546 | + * WordPress and to define internationalization functionality. |
|
| 547 | + * |
|
| 548 | + * @since 1.0.0 |
|
| 549 | + * @return string The name of the plugin. |
|
| 550 | + */ |
|
| 551 | + public function get_plugin_name() { |
|
| 552 | + return $this->plugin_name; |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + /** |
|
| 556 | + * The reference to the class that orchestrates the hooks with the plugin. |
|
| 557 | + * |
|
| 558 | + * @since 1.0.0 |
|
| 559 | + * @return Wordlift_Loader Orchestrates the hooks of the plugin. |
|
| 560 | + */ |
|
| 561 | + public function get_loader() { |
|
| 562 | + return $this->loader; |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * Retrieve the version number of the plugin. |
|
| 567 | + * |
|
| 568 | + * @since 1.0.0 |
|
| 569 | + * @return string The version number of the plugin. |
|
| 570 | + */ |
|
| 571 | + public function get_version() { |
|
| 572 | + return $this->version; |
|
| 573 | + } |
|
| 574 | 574 | |
| 575 | 575 | } |
@@ -243,136 +243,136 @@ discard block |
||
| 243 | 243 | * The class responsible for orchestrating the actions and filters of the |
| 244 | 244 | * core plugin. |
| 245 | 245 | */ |
| 246 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-loader.php'; |
|
| 246 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-loader.php'; |
|
| 247 | 247 | |
| 248 | 248 | /** |
| 249 | 249 | * The class responsible for defining internationalization functionality |
| 250 | 250 | * of the plugin. |
| 251 | 251 | */ |
| 252 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-i18n.php'; |
|
| 252 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-i18n.php'; |
|
| 253 | 253 | |
| 254 | 254 | /** |
| 255 | 255 | * The Redirect service. |
| 256 | 256 | */ |
| 257 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-redirect-service.php'; |
|
| 257 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-redirect-service.php'; |
|
| 258 | 258 | |
| 259 | 259 | /** |
| 260 | 260 | * The Log service. |
| 261 | 261 | */ |
| 262 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-log-service.php'; |
|
| 262 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-log-service.php'; |
|
| 263 | 263 | |
| 264 | 264 | /** |
| 265 | 265 | * The entity post type service. |
| 266 | 266 | */ |
| 267 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-type-service.php'; |
|
| 267 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-entity-type-service.php'; |
|
| 268 | 268 | |
| 269 | 269 | /** |
| 270 | 270 | * The entity link service. |
| 271 | 271 | */ |
| 272 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-link-service.php'; |
|
| 272 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-entity-link-service.php'; |
|
| 273 | 273 | |
| 274 | 274 | /** |
| 275 | 275 | * The Query builder. |
| 276 | 276 | */ |
| 277 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-query-builder.php'; |
|
| 277 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-query-builder.php'; |
|
| 278 | 278 | |
| 279 | 279 | /** |
| 280 | 280 | * The Schema service. |
| 281 | 281 | */ |
| 282 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-schema-service.php'; |
|
| 282 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-schema-service.php'; |
|
| 283 | 283 | |
| 284 | 284 | /** |
| 285 | 285 | * The UI service. |
| 286 | 286 | */ |
| 287 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-ui-service.php'; |
|
| 287 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-ui-service.php'; |
|
| 288 | 288 | |
| 289 | 289 | /** |
| 290 | 290 | * The Thumbnail service. |
| 291 | 291 | */ |
| 292 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-thumbnail-service.php'; |
|
| 292 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-thumbnail-service.php'; |
|
| 293 | 293 | |
| 294 | 294 | /** |
| 295 | 295 | * The Entity Types Taxonomy service. |
| 296 | 296 | */ |
| 297 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-types-taxonomy-service.php'; |
|
| 297 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-entity-types-taxonomy-service.php'; |
|
| 298 | 298 | |
| 299 | 299 | /** |
| 300 | 300 | * The Entity service. |
| 301 | 301 | */ |
| 302 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-entity-service.php'; |
|
| 302 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-entity-service.php'; |
|
| 303 | 303 | |
| 304 | 304 | /** |
| 305 | 305 | * The User service. |
| 306 | 306 | */ |
| 307 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-user-service.php'; |
|
| 307 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-user-service.php'; |
|
| 308 | 308 | |
| 309 | 309 | /** |
| 310 | 310 | * The Timeline service. |
| 311 | 311 | */ |
| 312 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-timeline-service.php'; |
|
| 312 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-timeline-service.php'; |
|
| 313 | 313 | |
| 314 | 314 | /** |
| 315 | 315 | * The Topic Taxonomy service. |
| 316 | 316 | */ |
| 317 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordlift-topic-taxonomy-service.php'; |
|
| 317 | + require_once plugin_dir_path(dirname(__FILE__)).'includes/class-wordlift-topic-taxonomy-service.php'; |
|
| 318 | 318 | |
| 319 | 319 | /** |
| 320 | 320 | * The class responsible for defining all actions that occur in the admin area. |
| 321 | 321 | */ |
| 322 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin.php'; |
|
| 322 | + require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin.php'; |
|
| 323 | 323 | |
| 324 | 324 | /** |
| 325 | 325 | * The class to customize the entity list admin page. |
| 326 | 326 | */ |
| 327 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-entity-list.php'; |
|
| 327 | + require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-entity-list.php'; |
|
| 328 | 328 | |
| 329 | 329 | /** |
| 330 | 330 | * The Entity Types Taxonomy Walker (transforms checkboxes into radios). |
| 331 | 331 | */ |
| 332 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-entity-types-taxonomy-walker.php'; |
|
| 332 | + require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-entity-types-taxonomy-walker.php'; |
|
| 333 | 333 | |
| 334 | 334 | /** |
| 335 | 335 | * The Notice service. |
| 336 | 336 | */ |
| 337 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-notice-service.php'; |
|
| 337 | + require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-notice-service.php'; |
|
| 338 | 338 | |
| 339 | 339 | /** |
| 340 | 340 | * The PrimaShop adapter. |
| 341 | 341 | */ |
| 342 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-primashop-adapter.php'; |
|
| 342 | + require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-primashop-adapter.php'; |
|
| 343 | 343 | |
| 344 | 344 | /** |
| 345 | 345 | * The WordLift Dashboard service. |
| 346 | 346 | */ |
| 347 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordlift-admin-dashboard.php'; |
|
| 347 | + require_once plugin_dir_path(dirname(__FILE__)).'admin/class-wordlift-admin-dashboard.php'; |
|
| 348 | 348 | |
| 349 | 349 | /** |
| 350 | 350 | * The class responsible for defining all actions that occur in the public-facing |
| 351 | 351 | * side of the site. |
| 352 | 352 | */ |
| 353 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-public.php'; |
|
| 353 | + require_once plugin_dir_path(dirname(__FILE__)).'public/class-wordlift-public.php'; |
|
| 354 | 354 | |
| 355 | 355 | /** |
| 356 | 356 | * The Timeline shortcode. |
| 357 | 357 | */ |
| 358 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-timeline-shortcode.php'; |
|
| 358 | + require_once plugin_dir_path(dirname(__FILE__)).'public/class-wordlift-timeline-shortcode.php'; |
|
| 359 | 359 | |
| 360 | 360 | /** |
| 361 | 361 | * The ShareThis service. |
| 362 | 362 | */ |
| 363 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordlift-sharethis-service.php'; |
|
| 363 | + require_once plugin_dir_path(dirname(__FILE__)).'public/class-wordlift-sharethis-service.php'; |
|
| 364 | 364 | |
| 365 | 365 | $this->loader = new Wordlift_Loader(); |
| 366 | 366 | |
| 367 | 367 | // Instantiate a global logger. |
| 368 | 368 | global $wl_logger; |
| 369 | - $wl_logger = Wordlift_Log_Service::get_logger( 'WordLift' ); |
|
| 369 | + $wl_logger = Wordlift_Log_Service::get_logger('WordLift'); |
|
| 370 | 370 | |
| 371 | 371 | // Create an entity type service instance. It'll be later bound to the init action. |
| 372 | - $this->entity_type_service = new Wordlift_Entity_Type_Service( Wordlift_Entity_Service::TYPE_NAME, WL_ENTITY_TYPE_SLUG ); |
|
| 372 | + $this->entity_type_service = new Wordlift_Entity_Type_Service(Wordlift_Entity_Service::TYPE_NAME, WL_ENTITY_TYPE_SLUG); |
|
| 373 | 373 | |
| 374 | 374 | // Create an entity link service instance. It'll be later bound to the post_type_link and pre_get_posts actions. |
| 375 | - $this->entity_link_service = new Wordlift_Entity_Link_Service( $this->entity_type_service, WL_ENTITY_TYPE_SLUG ); |
|
| 375 | + $this->entity_link_service = new Wordlift_Entity_Link_Service($this->entity_type_service, WL_ENTITY_TYPE_SLUG); |
|
| 376 | 376 | |
| 377 | 377 | // Create an instance of the UI service. |
| 378 | 378 | $this->ui_service = new Wordlift_UI_Service(); |
@@ -387,25 +387,25 @@ discard block |
||
| 387 | 387 | $this->notice_service = new Wordlift_Notice_Service(); |
| 388 | 388 | |
| 389 | 389 | // Create an instance of the Entity service, passing the UI service to draw parts of the Entity admin page. |
| 390 | - $this->entity_service = new Wordlift_Entity_Service( $this->ui_service, $this->schema_service, $this->notice_service ); |
|
| 390 | + $this->entity_service = new Wordlift_Entity_Service($this->ui_service, $this->schema_service, $this->notice_service); |
|
| 391 | 391 | |
| 392 | 392 | // Create an instance of the User service. |
| 393 | 393 | $this->user_service = new Wordlift_User_Service(); |
| 394 | 394 | |
| 395 | 395 | // Create a new instance of the Timeline service and Timeline shortcode. |
| 396 | - $this->timeline_service = new Wordlift_Timeline_Service( $this->entity_service ); |
|
| 396 | + $this->timeline_service = new Wordlift_Timeline_Service($this->entity_service); |
|
| 397 | 397 | |
| 398 | 398 | // Create a new instance of the Redirect service. |
| 399 | - $this->redirect_service = new Wordlift_Redirect_Service( $this->entity_service ); |
|
| 399 | + $this->redirect_service = new Wordlift_Redirect_Service($this->entity_service); |
|
| 400 | 400 | |
| 401 | 401 | // Create a new instance of the Redirect service. |
| 402 | - $this->dashboard_service = new Wordlift_Dashboard_Service( $this->entity_service ); |
|
| 402 | + $this->dashboard_service = new Wordlift_Dashboard_Service($this->entity_service); |
|
| 403 | 403 | |
| 404 | 404 | // Create an instance of the Timeline shortcode. |
| 405 | 405 | new Wordlift_Timeline_Shortcode(); |
| 406 | 406 | |
| 407 | 407 | // Create entity list customization (wp-admin/edit.php) |
| 408 | - $this->entity_list_service = new Wordlift_Entity_List_Service( $this->entity_service ); |
|
| 408 | + $this->entity_list_service = new Wordlift_Entity_List_Service($this->entity_service); |
|
| 409 | 409 | |
| 410 | 410 | $this->entity_types_taxonomy_walker = new Wordlift_Entity_Types_Taxonomy_Walker(); |
| 411 | 411 | |
@@ -430,9 +430,9 @@ discard block |
||
| 430 | 430 | private function set_locale() { |
| 431 | 431 | |
| 432 | 432 | $plugin_i18n = new Wordlift_i18n(); |
| 433 | - $plugin_i18n->set_domain( $this->get_plugin_name() ); |
|
| 433 | + $plugin_i18n->set_domain($this->get_plugin_name()); |
|
| 434 | 434 | |
| 435 | - $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); |
|
| 435 | + $this->loader->add_action('plugins_loaded', $plugin_i18n, 'load_plugin_textdomain'); |
|
| 436 | 436 | |
| 437 | 437 | } |
| 438 | 438 | |
@@ -445,59 +445,59 @@ discard block |
||
| 445 | 445 | */ |
| 446 | 446 | private function define_admin_hooks() { |
| 447 | 447 | |
| 448 | - $plugin_admin = new Wordlift_Admin( $this->get_plugin_name(), $this->get_version() ); |
|
| 448 | + $plugin_admin = new Wordlift_Admin($this->get_plugin_name(), $this->get_version()); |
|
| 449 | 449 | |
| 450 | - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); |
|
| 451 | - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); |
|
| 450 | + $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles'); |
|
| 451 | + $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts'); |
|
| 452 | 452 | |
| 453 | 453 | // Hook the init action to the Topic Taxonomy service. |
| 454 | - $this->loader->add_action( 'init', $this->topic_taxonomy_service, 'init', 0 ); |
|
| 454 | + $this->loader->add_action('init', $this->topic_taxonomy_service, 'init', 0); |
|
| 455 | 455 | |
| 456 | 456 | // Hook the deleted_post_meta action to the Thumbnail service. |
| 457 | - $this->loader->add_action( 'deleted_post_meta', $this->thumbnail_service, 'deleted_post_meta', 10, 4 ); |
|
| 457 | + $this->loader->add_action('deleted_post_meta', $this->thumbnail_service, 'deleted_post_meta', 10, 4); |
|
| 458 | 458 | |
| 459 | 459 | // Hook the added_post_meta action to the Thumbnail service. |
| 460 | - $this->loader->add_action( 'added_post_meta', $this->thumbnail_service, 'added_or_updated_post_meta', 10, 4 ); |
|
| 460 | + $this->loader->add_action('added_post_meta', $this->thumbnail_service, 'added_or_updated_post_meta', 10, 4); |
|
| 461 | 461 | |
| 462 | 462 | // Hook the updated_post_meta action to the Thumbnail service. |
| 463 | - $this->loader->add_action( 'updated_post_meta', $this->thumbnail_service, 'added_or_updated_post_meta', 10, 4 ); |
|
| 463 | + $this->loader->add_action('updated_post_meta', $this->thumbnail_service, 'added_or_updated_post_meta', 10, 4); |
|
| 464 | 464 | |
| 465 | 465 | // Hook posts inserts (or updates) to the user service. |
| 466 | - $this->loader->add_action( 'wp_insert_post', $this->user_service, 'wp_insert_post', 10, 3 ); |
|
| 466 | + $this->loader->add_action('wp_insert_post', $this->user_service, 'wp_insert_post', 10, 3); |
|
| 467 | 467 | |
| 468 | 468 | // Hook the AJAX wl_timeline action to the Timeline service. |
| 469 | - $this->loader->add_action( 'wp_ajax_wl_timeline', $this->timeline_service, 'ajax_timeline' ); |
|
| 469 | + $this->loader->add_action('wp_ajax_wl_timeline', $this->timeline_service, 'ajax_timeline'); |
|
| 470 | 470 | |
| 471 | 471 | // Register custom allowed redirect hosts. |
| 472 | - $this->loader->add_filter( 'allowed_redirect_hosts', $this->redirect_service, 'allowed_redirect_hosts' ); |
|
| 472 | + $this->loader->add_filter('allowed_redirect_hosts', $this->redirect_service, 'allowed_redirect_hosts'); |
|
| 473 | 473 | // Hook the AJAX wordlift_redirect action to the Redirect service. |
| 474 | - $this->loader->add_action( 'wp_ajax_wordlift_redirect', $this->redirect_service, 'ajax_redirect' ); |
|
| 474 | + $this->loader->add_action('wp_ajax_wordlift_redirect', $this->redirect_service, 'ajax_redirect'); |
|
| 475 | 475 | // Hook the AJAX wordlift_redirect action to the Redirect service. |
| 476 | - $this->loader->add_action( 'wp_ajax_wordlift_get_stats', $this->dashboard_service, 'ajax_get_stats' ); |
|
| 476 | + $this->loader->add_action('wp_ajax_wordlift_get_stats', $this->dashboard_service, 'ajax_get_stats'); |
|
| 477 | 477 | // Hook the AJAX wordlift_redirect action to the Redirect service. |
| 478 | - $this->loader->add_action( 'wp_dashboard_setup', $this->dashboard_service, 'add_dashboard_widgets' ); |
|
| 478 | + $this->loader->add_action('wp_dashboard_setup', $this->dashboard_service, 'add_dashboard_widgets'); |
|
| 479 | 479 | |
| 480 | 480 | // Hook save_post to the entity service to update custom fields (such as alternate labels). |
| 481 | 481 | // We have a priority of 9 because we want to be executed before data is sent to Redlink. |
| 482 | - $this->loader->add_action( 'save_post', $this->entity_service, 'save_post', 9, 3 ); |
|
| 483 | - $this->loader->add_action( 'save_post_entity', $this->entity_service, 'set_rating_for', 10, 1 ); |
|
| 482 | + $this->loader->add_action('save_post', $this->entity_service, 'save_post', 9, 3); |
|
| 483 | + $this->loader->add_action('save_post_entity', $this->entity_service, 'set_rating_for', 10, 1); |
|
| 484 | 484 | |
| 485 | - $this->loader->add_action( 'edit_form_before_permalink', $this->entity_service, 'edit_form_before_permalink', 10, 1 ); |
|
| 486 | - $this->loader->add_action( 'in_admin_header', $this->entity_service, 'in_admin_header' ); |
|
| 485 | + $this->loader->add_action('edit_form_before_permalink', $this->entity_service, 'edit_form_before_permalink', 10, 1); |
|
| 486 | + $this->loader->add_action('in_admin_header', $this->entity_service, 'in_admin_header'); |
|
| 487 | 487 | |
| 488 | 488 | // Entity listing customization (wp-admin/edit.php) |
| 489 | 489 | // Add custom columns |
| 490 | - $this->loader->add_filter( 'manage_entity_posts_columns', $this->entity_list_service, 'register_custom_columns' ); |
|
| 491 | - $this->loader->add_filter( 'manage_entity_posts_custom_column', $this->entity_list_service, 'render_custom_columns', 10, 2 ); |
|
| 490 | + $this->loader->add_filter('manage_entity_posts_columns', $this->entity_list_service, 'register_custom_columns'); |
|
| 491 | + $this->loader->add_filter('manage_entity_posts_custom_column', $this->entity_list_service, 'render_custom_columns', 10, 2); |
|
| 492 | 492 | // Add 4W selection |
| 493 | - $this->loader->add_action( 'restrict_manage_posts', $this->entity_list_service, 'restrict_manage_posts_classification_scope' ); |
|
| 494 | - $this->loader->add_filter( 'posts_clauses', $this->entity_list_service, 'posts_clauses_classification_scope' ); |
|
| 493 | + $this->loader->add_action('restrict_manage_posts', $this->entity_list_service, 'restrict_manage_posts_classification_scope'); |
|
| 494 | + $this->loader->add_filter('posts_clauses', $this->entity_list_service, 'posts_clauses_classification_scope'); |
|
| 495 | 495 | |
| 496 | - $this->loader->add_filter( 'wp_terms_checklist_args', $this->entity_types_taxonomy_walker, 'terms_checklist_args' ); |
|
| 496 | + $this->loader->add_filter('wp_terms_checklist_args', $this->entity_types_taxonomy_walker, 'terms_checklist_args'); |
|
| 497 | 497 | |
| 498 | 498 | // Hook the PrimaShop adapter to <em>prima_metabox_entity_header_args</em> in order to add header support for |
| 499 | 499 | // entities. |
| 500 | - $this->loader->add_filter( 'prima_metabox_entity_header_args', $this->primashop_adapter, 'prima_metabox_entity_header_args', 10, 2 ); |
|
| 500 | + $this->loader->add_filter('prima_metabox_entity_header_args', $this->primashop_adapter, 'prima_metabox_entity_header_args', 10, 2); |
|
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 503 | /** |
@@ -509,26 +509,26 @@ discard block |
||
| 509 | 509 | */ |
| 510 | 510 | private function define_public_hooks() { |
| 511 | 511 | |
| 512 | - $plugin_public = new Wordlift_Public( $this->get_plugin_name(), $this->get_version() ); |
|
| 512 | + $plugin_public = new Wordlift_Public($this->get_plugin_name(), $this->get_version()); |
|
| 513 | 513 | |
| 514 | 514 | // Register the entity post type. |
| 515 | - $this->loader->add_action( 'init', $this->entity_type_service, 'register' ); |
|
| 515 | + $this->loader->add_action('init', $this->entity_type_service, 'register'); |
|
| 516 | 516 | |
| 517 | 517 | // Bind the link generation and handling hooks to the entity link service. |
| 518 | - $this->loader->add_filter( 'post_type_link', $this->entity_link_service, 'post_type_link', 10, 4 ); |
|
| 519 | - $this->loader->add_action( 'pre_get_posts', $this->entity_link_service, 'pre_get_posts', 10, 1 ); |
|
| 520 | - $this->loader->add_filter( 'wp_unique_post_slug_is_bad_flat_slug', $this->entity_link_service, 'wp_unique_post_slug_is_bad_flat_slug', 10, 3 ); |
|
| 521 | - $this->loader->add_filter( 'wp_unique_post_slug_is_bad_hierarchical_slug', $this->entity_link_service, 'wp_unique_post_slug_is_bad_hierarchical_slug', 10, 4 ); |
|
| 518 | + $this->loader->add_filter('post_type_link', $this->entity_link_service, 'post_type_link', 10, 4); |
|
| 519 | + $this->loader->add_action('pre_get_posts', $this->entity_link_service, 'pre_get_posts', 10, 1); |
|
| 520 | + $this->loader->add_filter('wp_unique_post_slug_is_bad_flat_slug', $this->entity_link_service, 'wp_unique_post_slug_is_bad_flat_slug', 10, 3); |
|
| 521 | + $this->loader->add_filter('wp_unique_post_slug_is_bad_hierarchical_slug', $this->entity_link_service, 'wp_unique_post_slug_is_bad_hierarchical_slug', 10, 4); |
|
| 522 | 522 | |
| 523 | - $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); |
|
| 524 | - $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); |
|
| 523 | + $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_styles'); |
|
| 524 | + $this->loader->add_action('wp_enqueue_scripts', $plugin_public, 'enqueue_scripts'); |
|
| 525 | 525 | |
| 526 | 526 | // Hook the AJAX wl_timeline action to the Timeline service. |
| 527 | - $this->loader->add_action( 'wp_ajax_nopriv_wl_timeline', $this->timeline_service, 'ajax_timeline' ); |
|
| 527 | + $this->loader->add_action('wp_ajax_nopriv_wl_timeline', $this->timeline_service, 'ajax_timeline'); |
|
| 528 | 528 | |
| 529 | 529 | // Hook the ShareThis service. |
| 530 | - $this->loader->add_filter( 'the_content', $this->sharethis_service, 'the_content', 99 ); |
|
| 531 | - $this->loader->add_filter( 'the_excerpt', $this->sharethis_service, 'the_excerpt', 99 ); |
|
| 530 | + $this->loader->add_filter('the_content', $this->sharethis_service, 'the_content', 99); |
|
| 531 | + $this->loader->add_filter('the_excerpt', $this->sharethis_service, 'the_excerpt', 99); |
|
| 532 | 532 | |
| 533 | 533 | } |
| 534 | 534 | |
@@ -46,30 +46,30 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | // wl_write_log( "wl_set_entity_main_type [ post id :: $post_id ][ type uri :: $type_uri ]" ); |
| 48 | 48 | |
| 49 | - // If the type URI is empty we remove the type. |
|
| 50 | - if ( empty( $type_uri ) ) { |
|
| 51 | - wp_set_object_terms( $post_id, null, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 52 | - |
|
| 53 | - return; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - // Get all the terms bound to the wl_entity_type taxonomy. |
|
| 57 | - $terms = get_terms( Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array( |
|
| 58 | - 'hide_empty' => false, |
|
| 59 | - 'fields' => 'id=>slug' |
|
| 60 | - ) ); |
|
| 61 | - |
|
| 62 | - // Check which term matches the specified URI. |
|
| 63 | - foreach ( $terms as $term_id => $term_slug ) { |
|
| 64 | - // Load the type data. |
|
| 65 | - $type = Wordlift_Schema_Service::get_instance()->get_schema( $term_slug ); |
|
| 66 | - // Set the related term ID. |
|
| 67 | - if ( $type_uri === $type['uri'] || $type_uri === $type['css_class'] ) { |
|
| 68 | - wp_set_object_terms( $post_id, (int) $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 69 | - |
|
| 70 | - return; |
|
| 71 | - } |
|
| 72 | - } |
|
| 49 | + // If the type URI is empty we remove the type. |
|
| 50 | + if ( empty( $type_uri ) ) { |
|
| 51 | + wp_set_object_terms( $post_id, null, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 52 | + |
|
| 53 | + return; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + // Get all the terms bound to the wl_entity_type taxonomy. |
|
| 57 | + $terms = get_terms( Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array( |
|
| 58 | + 'hide_empty' => false, |
|
| 59 | + 'fields' => 'id=>slug' |
|
| 60 | + ) ); |
|
| 61 | + |
|
| 62 | + // Check which term matches the specified URI. |
|
| 63 | + foreach ( $terms as $term_id => $term_slug ) { |
|
| 64 | + // Load the type data. |
|
| 65 | + $type = Wordlift_Schema_Service::get_instance()->get_schema( $term_slug ); |
|
| 66 | + // Set the related term ID. |
|
| 67 | + if ( $type_uri === $type['uri'] || $type_uri === $type['css_class'] ) { |
|
| 68 | + wp_set_object_terms( $post_id, (int) $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 69 | + |
|
| 70 | + return; |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -77,46 +77,46 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | function wl_print_entity_type_inline_js() { |
| 79 | 79 | |
| 80 | - $terms = get_terms( Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array( |
|
| 81 | - 'hide_empty' => false |
|
| 82 | - ) ); |
|
| 80 | + $terms = get_terms( Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array( |
|
| 81 | + 'hide_empty' => false |
|
| 82 | + ) ); |
|
| 83 | 83 | |
| 84 | - echo <<<EOF |
|
| 84 | + echo <<<EOF |
|
| 85 | 85 | <script type="text/javascript"> |
| 86 | 86 | (function() { |
| 87 | 87 | var t = []; |
| 88 | 88 | |
| 89 | 89 | EOF; |
| 90 | 90 | |
| 91 | - // Cycle in each WordLift term and get its metadata. The metadata will be printed as a global object in JavaScript |
|
| 92 | - // to be used by the JavaScript client library. |
|
| 93 | - foreach ( $terms as $term ) { |
|
| 91 | + // Cycle in each WordLift term and get its metadata. The metadata will be printed as a global object in JavaScript |
|
| 92 | + // to be used by the JavaScript client library. |
|
| 93 | + foreach ( $terms as $term ) { |
|
| 94 | 94 | |
| 95 | - $term_name = $term->name; |
|
| 95 | + $term_name = $term->name; |
|
| 96 | 96 | |
| 97 | - // Load the type data. |
|
| 98 | - $type = Wordlift_Schema_Service::get_instance()->get_schema( $term->slug ); |
|
| 97 | + // Load the type data. |
|
| 98 | + $type = Wordlift_Schema_Service::get_instance()->get_schema( $term->slug ); |
|
| 99 | 99 | |
| 100 | - // Skip types that are not defined. |
|
| 101 | - if ( ! empty( $type['uri'] ) ) { |
|
| 100 | + // Skip types that are not defined. |
|
| 101 | + if ( ! empty( $type['uri'] ) ) { |
|
| 102 | 102 | |
| 103 | - // Prepare the JSON output then print it to the browser. |
|
| 104 | - $json = json_encode( array( |
|
| 105 | - 'label' => $term_name, |
|
| 106 | - 'uri' => $type['uri'], |
|
| 107 | - 'css' => $type['css_class'], |
|
| 108 | - 'sameAs' => $type['same_as'], |
|
| 109 | - 'templates' => ( isset( $type['templates'] ) ? $type['templates'] : array() ), |
|
| 110 | - ) ); |
|
| 103 | + // Prepare the JSON output then print it to the browser. |
|
| 104 | + $json = json_encode( array( |
|
| 105 | + 'label' => $term_name, |
|
| 106 | + 'uri' => $type['uri'], |
|
| 107 | + 'css' => $type['css_class'], |
|
| 108 | + 'sameAs' => $type['same_as'], |
|
| 109 | + 'templates' => ( isset( $type['templates'] ) ? $type['templates'] : array() ), |
|
| 110 | + ) ); |
|
| 111 | 111 | |
| 112 | - // Output the type data. |
|
| 113 | - echo "t.push($json);\n"; |
|
| 112 | + // Output the type data. |
|
| 113 | + echo "t.push($json);\n"; |
|
| 114 | 114 | |
| 115 | - } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - } |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - echo <<<EOF |
|
| 119 | + echo <<<EOF |
|
| 120 | 120 | if ('undefined' == typeof window.wordlift) { |
| 121 | 121 | window.wordlift = {} |
| 122 | 122 | } |
@@ -42,30 +42,30 @@ discard block |
||
| 42 | 42 | * @param int $post_id The numeric post ID. |
| 43 | 43 | * @param string $type_uri A type URI. |
| 44 | 44 | */ |
| 45 | -function wl_set_entity_main_type( $post_id, $type_uri ) { |
|
| 45 | +function wl_set_entity_main_type($post_id, $type_uri) { |
|
| 46 | 46 | |
| 47 | 47 | // wl_write_log( "wl_set_entity_main_type [ post id :: $post_id ][ type uri :: $type_uri ]" ); |
| 48 | 48 | |
| 49 | 49 | // If the type URI is empty we remove the type. |
| 50 | - if ( empty( $type_uri ) ) { |
|
| 51 | - wp_set_object_terms( $post_id, null, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 50 | + if (empty($type_uri)) { |
|
| 51 | + wp_set_object_terms($post_id, null, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME); |
|
| 52 | 52 | |
| 53 | 53 | return; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | // Get all the terms bound to the wl_entity_type taxonomy. |
| 57 | - $terms = get_terms( Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array( |
|
| 57 | + $terms = get_terms(Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array( |
|
| 58 | 58 | 'hide_empty' => false, |
| 59 | 59 | 'fields' => 'id=>slug' |
| 60 | - ) ); |
|
| 60 | + )); |
|
| 61 | 61 | |
| 62 | 62 | // Check which term matches the specified URI. |
| 63 | - foreach ( $terms as $term_id => $term_slug ) { |
|
| 63 | + foreach ($terms as $term_id => $term_slug) { |
|
| 64 | 64 | // Load the type data. |
| 65 | - $type = Wordlift_Schema_Service::get_instance()->get_schema( $term_slug ); |
|
| 65 | + $type = Wordlift_Schema_Service::get_instance()->get_schema($term_slug); |
|
| 66 | 66 | // Set the related term ID. |
| 67 | - if ( $type_uri === $type['uri'] || $type_uri === $type['css_class'] ) { |
|
| 68 | - wp_set_object_terms( $post_id, (int) $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 67 | + if ($type_uri === $type['uri'] || $type_uri === $type['css_class']) { |
|
| 68 | + wp_set_object_terms($post_id, (int) $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME); |
|
| 69 | 69 | |
| 70 | 70 | return; |
| 71 | 71 | } |
@@ -77,9 +77,9 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | function wl_print_entity_type_inline_js() { |
| 79 | 79 | |
| 80 | - $terms = get_terms( Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array( |
|
| 80 | + $terms = get_terms(Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array( |
|
| 81 | 81 | 'hide_empty' => false |
| 82 | - ) ); |
|
| 82 | + )); |
|
| 83 | 83 | |
| 84 | 84 | echo <<<EOF |
| 85 | 85 | <script type="text/javascript"> |
@@ -90,24 +90,24 @@ discard block |
||
| 90 | 90 | |
| 91 | 91 | // Cycle in each WordLift term and get its metadata. The metadata will be printed as a global object in JavaScript |
| 92 | 92 | // to be used by the JavaScript client library. |
| 93 | - foreach ( $terms as $term ) { |
|
| 93 | + foreach ($terms as $term) { |
|
| 94 | 94 | |
| 95 | 95 | $term_name = $term->name; |
| 96 | 96 | |
| 97 | 97 | // Load the type data. |
| 98 | - $type = Wordlift_Schema_Service::get_instance()->get_schema( $term->slug ); |
|
| 98 | + $type = Wordlift_Schema_Service::get_instance()->get_schema($term->slug); |
|
| 99 | 99 | |
| 100 | 100 | // Skip types that are not defined. |
| 101 | - if ( ! empty( $type['uri'] ) ) { |
|
| 101 | + if ( ! empty($type['uri'])) { |
|
| 102 | 102 | |
| 103 | 103 | // Prepare the JSON output then print it to the browser. |
| 104 | - $json = json_encode( array( |
|
| 104 | + $json = json_encode(array( |
|
| 105 | 105 | 'label' => $term_name, |
| 106 | 106 | 'uri' => $type['uri'], |
| 107 | 107 | 'css' => $type['css_class'], |
| 108 | 108 | 'sameAs' => $type['same_as'], |
| 109 | - 'templates' => ( isset( $type['templates'] ) ? $type['templates'] : array() ), |
|
| 110 | - ) ); |
|
| 109 | + 'templates' => (isset($type['templates']) ? $type['templates'] : array()), |
|
| 110 | + )); |
|
| 111 | 111 | |
| 112 | 112 | // Output the type data. |
| 113 | 113 | echo "t.push($json);\n"; |
@@ -128,6 +128,6 @@ discard block |
||
| 128 | 128 | |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | -add_action( 'admin_print_scripts', 'wl_print_entity_type_inline_js' ); |
|
| 131 | +add_action('admin_print_scripts', 'wl_print_entity_type_inline_js'); |
|
| 132 | 132 | |
| 133 | -add_action( 'init', 'wl_entity_type_taxonomy_register', 0 ); |
|
| 133 | +add_action('init', 'wl_entity_type_taxonomy_register', 0); |
|