@@ -15,120 +15,120 @@ discard block |
||
| 15 | 15 | * @subpackage Wordlift/install |
| 16 | 16 | */ |
| 17 | 17 | class Wordlift_Install_1_0_0 extends Wordlift_Install { |
| 18 | - /** |
|
| 19 | - * @inheritdoc |
|
| 20 | - */ |
|
| 21 | - protected static $version = '1.0.0'; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * The WordLift entity type terms. |
|
| 25 | - * |
|
| 26 | - * @since 3.18.0 |
|
| 27 | - * @access private |
|
| 28 | - * @var array $terms The entity type terms. |
|
| 29 | - */ |
|
| 30 | - private static $terms = array( |
|
| 31 | - 'thing' => array( |
|
| 32 | - 'label' => 'Thing', |
|
| 33 | - 'description' => 'A generic thing (something that doesn\'t fit in the previous definitions.', |
|
| 34 | - ), |
|
| 35 | - 'creative-work' => array( |
|
| 36 | - 'label' => 'CreativeWork', |
|
| 37 | - 'description' => 'A creative work (or a Music Album).', |
|
| 38 | - ), |
|
| 39 | - 'event' => array( |
|
| 40 | - 'label' => 'Event', |
|
| 41 | - 'description' => 'An event.', |
|
| 42 | - ), |
|
| 43 | - 'organization' => array( |
|
| 44 | - 'label' => 'Organization', |
|
| 45 | - 'description' => 'An organization, including a government or a newspaper.', |
|
| 46 | - ), |
|
| 47 | - 'person' => array( |
|
| 48 | - 'label' => 'Person', |
|
| 49 | - 'description' => 'A person (or a music artist).', |
|
| 50 | - ), |
|
| 51 | - 'place' => array( |
|
| 52 | - 'label' => 'Place', |
|
| 53 | - 'description' => 'A place.', |
|
| 54 | - ), |
|
| 55 | - 'localbusiness' => array( |
|
| 56 | - 'label' => 'LocalBusiness', |
|
| 57 | - 'description' => 'A local business.', |
|
| 58 | - ), |
|
| 59 | - ); |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @inheritdoc |
|
| 63 | - */ |
|
| 64 | - public function install() { |
|
| 65 | - // Set the dataset uri. |
|
| 66 | - $this->set_dataset_uri(); |
|
| 67 | - |
|
| 68 | - // Create entity type terms. |
|
| 69 | - $this->create_entity_type_terms(); |
|
| 70 | - |
|
| 71 | - // Create relations table. |
|
| 72 | - $this->create_relation_instance_table(); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Create required entity type terms |
|
| 77 | - * |
|
| 78 | - * @since 3.18.0 |
|
| 79 | - * |
|
| 80 | - * @return void |
|
| 81 | - */ |
|
| 82 | - private function create_entity_type_terms() { |
|
| 83 | - $this->log->debug( 'Installing Entity Type data...' ); |
|
| 84 | - |
|
| 85 | - // Set the taxonomy data. |
|
| 86 | - // Note: parent types must be defined before child types. |
|
| 87 | - foreach ( self::$terms as $slug => $term ) { |
|
| 88 | - |
|
| 89 | - // Check whether the term exists and create it if it doesn't. |
|
| 90 | - $term_id = $this->get_term_or_create_if_not_exists( $slug ); |
|
| 91 | - |
|
| 92 | - // Bail if the term doesn't exists or it's not created. |
|
| 93 | - if ( empty( $term_id ) ) { |
|
| 94 | - continue; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - // Update term with description, slug and parent. |
|
| 98 | - $term = wp_update_term( |
|
| 99 | - $term_id, |
|
| 100 | - Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
| 101 | - array( |
|
| 102 | - 'name' => $term['label'], |
|
| 103 | - 'slug' => $slug, |
|
| 104 | - 'description' => $term['description'], |
|
| 105 | - // We give to WP taxonomy just one parent. |
|
| 106 | - 'parent' => 0, |
|
| 107 | - ) |
|
| 108 | - ); |
|
| 109 | - |
|
| 110 | - $this->log->trace( "Entity Type $slug installed with ID {$term['term_id']}." ); |
|
| 111 | - |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - $this->log->debug( 'Entity Type data installed.' ); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Install custom relations table. |
|
| 119 | - * |
|
| 120 | - * @since 3.8.0 |
|
| 121 | - * |
|
| 122 | - * @return void |
|
| 123 | - */ |
|
| 124 | - private function create_relation_instance_table() { |
|
| 125 | - global $wpdb; |
|
| 126 | - |
|
| 127 | - $table_name = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME; |
|
| 128 | - $charset_collate = $wpdb->get_charset_collate(); |
|
| 129 | - |
|
| 130 | - // Sql statement for the relation instances custom table. |
|
| 131 | - $sql = <<<EOF |
|
| 18 | + /** |
|
| 19 | + * @inheritdoc |
|
| 20 | + */ |
|
| 21 | + protected static $version = '1.0.0'; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * The WordLift entity type terms. |
|
| 25 | + * |
|
| 26 | + * @since 3.18.0 |
|
| 27 | + * @access private |
|
| 28 | + * @var array $terms The entity type terms. |
|
| 29 | + */ |
|
| 30 | + private static $terms = array( |
|
| 31 | + 'thing' => array( |
|
| 32 | + 'label' => 'Thing', |
|
| 33 | + 'description' => 'A generic thing (something that doesn\'t fit in the previous definitions.', |
|
| 34 | + ), |
|
| 35 | + 'creative-work' => array( |
|
| 36 | + 'label' => 'CreativeWork', |
|
| 37 | + 'description' => 'A creative work (or a Music Album).', |
|
| 38 | + ), |
|
| 39 | + 'event' => array( |
|
| 40 | + 'label' => 'Event', |
|
| 41 | + 'description' => 'An event.', |
|
| 42 | + ), |
|
| 43 | + 'organization' => array( |
|
| 44 | + 'label' => 'Organization', |
|
| 45 | + 'description' => 'An organization, including a government or a newspaper.', |
|
| 46 | + ), |
|
| 47 | + 'person' => array( |
|
| 48 | + 'label' => 'Person', |
|
| 49 | + 'description' => 'A person (or a music artist).', |
|
| 50 | + ), |
|
| 51 | + 'place' => array( |
|
| 52 | + 'label' => 'Place', |
|
| 53 | + 'description' => 'A place.', |
|
| 54 | + ), |
|
| 55 | + 'localbusiness' => array( |
|
| 56 | + 'label' => 'LocalBusiness', |
|
| 57 | + 'description' => 'A local business.', |
|
| 58 | + ), |
|
| 59 | + ); |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @inheritdoc |
|
| 63 | + */ |
|
| 64 | + public function install() { |
|
| 65 | + // Set the dataset uri. |
|
| 66 | + $this->set_dataset_uri(); |
|
| 67 | + |
|
| 68 | + // Create entity type terms. |
|
| 69 | + $this->create_entity_type_terms(); |
|
| 70 | + |
|
| 71 | + // Create relations table. |
|
| 72 | + $this->create_relation_instance_table(); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Create required entity type terms |
|
| 77 | + * |
|
| 78 | + * @since 3.18.0 |
|
| 79 | + * |
|
| 80 | + * @return void |
|
| 81 | + */ |
|
| 82 | + private function create_entity_type_terms() { |
|
| 83 | + $this->log->debug( 'Installing Entity Type data...' ); |
|
| 84 | + |
|
| 85 | + // Set the taxonomy data. |
|
| 86 | + // Note: parent types must be defined before child types. |
|
| 87 | + foreach ( self::$terms as $slug => $term ) { |
|
| 88 | + |
|
| 89 | + // Check whether the term exists and create it if it doesn't. |
|
| 90 | + $term_id = $this->get_term_or_create_if_not_exists( $slug ); |
|
| 91 | + |
|
| 92 | + // Bail if the term doesn't exists or it's not created. |
|
| 93 | + if ( empty( $term_id ) ) { |
|
| 94 | + continue; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + // Update term with description, slug and parent. |
|
| 98 | + $term = wp_update_term( |
|
| 99 | + $term_id, |
|
| 100 | + Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
| 101 | + array( |
|
| 102 | + 'name' => $term['label'], |
|
| 103 | + 'slug' => $slug, |
|
| 104 | + 'description' => $term['description'], |
|
| 105 | + // We give to WP taxonomy just one parent. |
|
| 106 | + 'parent' => 0, |
|
| 107 | + ) |
|
| 108 | + ); |
|
| 109 | + |
|
| 110 | + $this->log->trace( "Entity Type $slug installed with ID {$term['term_id']}." ); |
|
| 111 | + |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + $this->log->debug( 'Entity Type data installed.' ); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Install custom relations table. |
|
| 119 | + * |
|
| 120 | + * @since 3.8.0 |
|
| 121 | + * |
|
| 122 | + * @return void |
|
| 123 | + */ |
|
| 124 | + private function create_relation_instance_table() { |
|
| 125 | + global $wpdb; |
|
| 126 | + |
|
| 127 | + $table_name = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME; |
|
| 128 | + $charset_collate = $wpdb->get_charset_collate(); |
|
| 129 | + |
|
| 130 | + // Sql statement for the relation instances custom table. |
|
| 131 | + $sql = <<<EOF |
|
| 132 | 132 | CREATE TABLE $table_name ( |
| 133 | 133 | id int(11) NOT NULL AUTO_INCREMENT, |
| 134 | 134 | subject_id int(11) NOT NULL, |
@@ -140,66 +140,66 @@ discard block |
||
| 140 | 140 | ) $charset_collate; |
| 141 | 141 | EOF; |
| 142 | 142 | |
| 143 | - // @see: https://codex.wordpress.org/Creating_Tables_with_Plugins |
|
| 144 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
| 145 | - $results = dbDelta( $sql ); |
|
| 146 | - |
|
| 147 | - $this->log->trace( 'create_relation_instance_table :: ' . var_export( $results, true ) ); |
|
| 148 | - |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Configure the dataset uri. |
|
| 153 | - * |
|
| 154 | - * @since 3.18.0 |
|
| 155 | - * |
|
| 156 | - * @return void |
|
| 157 | - */ |
|
| 158 | - private function set_dataset_uri() { |
|
| 159 | - // Get the configuration service and load the key. |
|
| 160 | - $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
| 161 | - $key = $configuration_service->get_key(); |
|
| 162 | - |
|
| 163 | - // If the key is not empty then set the dataset URI while sending |
|
| 164 | - // the site URL. |
|
| 165 | - if ( ! empty( $key ) ) { |
|
| 166 | - $this->log->info( 'Updating the remote dataset URI...' ); |
|
| 167 | - |
|
| 168 | - $configuration_service->get_remote_dataset_uri( $key ); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Checks whether the term exists and create it if it doesn't. |
|
| 175 | - * |
|
| 176 | - * @since 3.18.0 |
|
| 177 | - * |
|
| 178 | - * @param string $slug Term slug. |
|
| 179 | - * |
|
| 180 | - * @return mixed Term id if the term exists or if it's created. False on failure |
|
| 181 | - */ |
|
| 182 | - private function get_term_or_create_if_not_exists( $slug ) { |
|
| 183 | - // Create the term if it does not exist, then get its ID. |
|
| 184 | - $term_id = term_exists( $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 185 | - |
|
| 186 | - if ( empty( $term_id ) ) { |
|
| 187 | - // The term doesn't exists, so create it. |
|
| 188 | - $maybe_term = wp_insert_term( $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 189 | - } else { |
|
| 190 | - // Get the term. |
|
| 191 | - $maybe_term = get_term( $term_id['term_id'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A ); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - // Check for errors. |
|
| 195 | - if ( is_wp_error( $maybe_term ) ) { |
|
| 196 | - $this->log->info( 'wl_install_entity_type_data [ ' . $maybe_term->get_error_message() . ' ]' ); |
|
| 197 | - |
|
| 198 | - return false; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // Finally return the term id. |
|
| 202 | - return $maybe_term['term_id']; |
|
| 203 | - } |
|
| 143 | + // @see: https://codex.wordpress.org/Creating_Tables_with_Plugins |
|
| 144 | + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
| 145 | + $results = dbDelta( $sql ); |
|
| 146 | + |
|
| 147 | + $this->log->trace( 'create_relation_instance_table :: ' . var_export( $results, true ) ); |
|
| 148 | + |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Configure the dataset uri. |
|
| 153 | + * |
|
| 154 | + * @since 3.18.0 |
|
| 155 | + * |
|
| 156 | + * @return void |
|
| 157 | + */ |
|
| 158 | + private function set_dataset_uri() { |
|
| 159 | + // Get the configuration service and load the key. |
|
| 160 | + $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
| 161 | + $key = $configuration_service->get_key(); |
|
| 162 | + |
|
| 163 | + // If the key is not empty then set the dataset URI while sending |
|
| 164 | + // the site URL. |
|
| 165 | + if ( ! empty( $key ) ) { |
|
| 166 | + $this->log->info( 'Updating the remote dataset URI...' ); |
|
| 167 | + |
|
| 168 | + $configuration_service->get_remote_dataset_uri( $key ); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Checks whether the term exists and create it if it doesn't. |
|
| 175 | + * |
|
| 176 | + * @since 3.18.0 |
|
| 177 | + * |
|
| 178 | + * @param string $slug Term slug. |
|
| 179 | + * |
|
| 180 | + * @return mixed Term id if the term exists or if it's created. False on failure |
|
| 181 | + */ |
|
| 182 | + private function get_term_or_create_if_not_exists( $slug ) { |
|
| 183 | + // Create the term if it does not exist, then get its ID. |
|
| 184 | + $term_id = term_exists( $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 185 | + |
|
| 186 | + if ( empty( $term_id ) ) { |
|
| 187 | + // The term doesn't exists, so create it. |
|
| 188 | + $maybe_term = wp_insert_term( $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 189 | + } else { |
|
| 190 | + // Get the term. |
|
| 191 | + $maybe_term = get_term( $term_id['term_id'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A ); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + // Check for errors. |
|
| 195 | + if ( is_wp_error( $maybe_term ) ) { |
|
| 196 | + $this->log->info( 'wl_install_entity_type_data [ ' . $maybe_term->get_error_message() . ' ]' ); |
|
| 197 | + |
|
| 198 | + return false; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // Finally return the term id. |
|
| 202 | + return $maybe_term['term_id']; |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | 205 | } |
@@ -80,17 +80,17 @@ discard block |
||
| 80 | 80 | * @return void |
| 81 | 81 | */ |
| 82 | 82 | private function create_entity_type_terms() { |
| 83 | - $this->log->debug( 'Installing Entity Type data...' ); |
|
| 83 | + $this->log->debug('Installing Entity Type data...'); |
|
| 84 | 84 | |
| 85 | 85 | // Set the taxonomy data. |
| 86 | 86 | // Note: parent types must be defined before child types. |
| 87 | - foreach ( self::$terms as $slug => $term ) { |
|
| 87 | + foreach (self::$terms as $slug => $term) { |
|
| 88 | 88 | |
| 89 | 89 | // Check whether the term exists and create it if it doesn't. |
| 90 | - $term_id = $this->get_term_or_create_if_not_exists( $slug ); |
|
| 90 | + $term_id = $this->get_term_or_create_if_not_exists($slug); |
|
| 91 | 91 | |
| 92 | 92 | // Bail if the term doesn't exists or it's not created. |
| 93 | - if ( empty( $term_id ) ) { |
|
| 93 | + if (empty($term_id)) { |
|
| 94 | 94 | continue; |
| 95 | 95 | } |
| 96 | 96 | |
@@ -107,11 +107,11 @@ discard block |
||
| 107 | 107 | ) |
| 108 | 108 | ); |
| 109 | 109 | |
| 110 | - $this->log->trace( "Entity Type $slug installed with ID {$term['term_id']}." ); |
|
| 110 | + $this->log->trace("Entity Type $slug installed with ID {$term['term_id']}."); |
|
| 111 | 111 | |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - $this->log->debug( 'Entity Type data installed.' ); |
|
| 114 | + $this->log->debug('Entity Type data installed.'); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | private function create_relation_instance_table() { |
| 125 | 125 | global $wpdb; |
| 126 | 126 | |
| 127 | - $table_name = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME; |
|
| 127 | + $table_name = $wpdb->prefix.WL_DB_RELATION_INSTANCES_TABLE_NAME; |
|
| 128 | 128 | $charset_collate = $wpdb->get_charset_collate(); |
| 129 | 129 | |
| 130 | 130 | // Sql statement for the relation instances custom table. |
@@ -141,10 +141,10 @@ discard block |
||
| 141 | 141 | EOF; |
| 142 | 142 | |
| 143 | 143 | // @see: https://codex.wordpress.org/Creating_Tables_with_Plugins |
| 144 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
| 145 | - $results = dbDelta( $sql ); |
|
| 144 | + require_once(ABSPATH.'wp-admin/includes/upgrade.php'); |
|
| 145 | + $results = dbDelta($sql); |
|
| 146 | 146 | |
| 147 | - $this->log->trace( 'create_relation_instance_table :: ' . var_export( $results, true ) ); |
|
| 147 | + $this->log->trace('create_relation_instance_table :: '.var_export($results, true)); |
|
| 148 | 148 | |
| 149 | 149 | } |
| 150 | 150 | |
@@ -162,10 +162,10 @@ discard block |
||
| 162 | 162 | |
| 163 | 163 | // If the key is not empty then set the dataset URI while sending |
| 164 | 164 | // the site URL. |
| 165 | - if ( ! empty( $key ) ) { |
|
| 166 | - $this->log->info( 'Updating the remote dataset URI...' ); |
|
| 165 | + if ( ! empty($key)) { |
|
| 166 | + $this->log->info('Updating the remote dataset URI...'); |
|
| 167 | 167 | |
| 168 | - $configuration_service->get_remote_dataset_uri( $key ); |
|
| 168 | + $configuration_service->get_remote_dataset_uri($key); |
|
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | } |
@@ -179,21 +179,21 @@ discard block |
||
| 179 | 179 | * |
| 180 | 180 | * @return mixed Term id if the term exists or if it's created. False on failure |
| 181 | 181 | */ |
| 182 | - private function get_term_or_create_if_not_exists( $slug ) { |
|
| 182 | + private function get_term_or_create_if_not_exists($slug) { |
|
| 183 | 183 | // Create the term if it does not exist, then get its ID. |
| 184 | - $term_id = term_exists( $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 184 | + $term_id = term_exists($slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME); |
|
| 185 | 185 | |
| 186 | - if ( empty( $term_id ) ) { |
|
| 186 | + if (empty($term_id)) { |
|
| 187 | 187 | // The term doesn't exists, so create it. |
| 188 | - $maybe_term = wp_insert_term( $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 188 | + $maybe_term = wp_insert_term($slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME); |
|
| 189 | 189 | } else { |
| 190 | 190 | // Get the term. |
| 191 | - $maybe_term = get_term( $term_id['term_id'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A ); |
|
| 191 | + $maybe_term = get_term($term_id['term_id'], Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | // Check for errors. |
| 195 | - if ( is_wp_error( $maybe_term ) ) { |
|
| 196 | - $this->log->info( 'wl_install_entity_type_data [ ' . $maybe_term->get_error_message() . ' ]' ); |
|
| 195 | + if (is_wp_error($maybe_term)) { |
|
| 196 | + $this->log->info('wl_install_entity_type_data [ '.$maybe_term->get_error_message().' ]'); |
|
| 197 | 197 | |
| 198 | 198 | return false; |
| 199 | 199 | } |
@@ -12,68 +12,68 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class Wordlift_Install_3_20_0 extends Wordlift_Install { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * {@inheritdoc} |
|
| 17 | - */ |
|
| 18 | - protected static $version = '3.20.0'; |
|
| 15 | + /** |
|
| 16 | + * {@inheritdoc} |
|
| 17 | + */ |
|
| 18 | + protected static $version = '3.20.0'; |
|
| 19 | 19 | |
| 20 | - public function install() { |
|
| 20 | + public function install() { |
|
| 21 | 21 | |
| 22 | - $this->add_names_to_existing_terms(); |
|
| 23 | - $this->rename_localbusiness_to_local_business(); |
|
| 22 | + $this->add_names_to_existing_terms(); |
|
| 23 | + $this->rename_localbusiness_to_local_business(); |
|
| 24 | 24 | |
| 25 | - } |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - private function add_names_to_existing_terms() { |
|
| 27 | + private function add_names_to_existing_terms() { |
|
| 28 | 28 | |
| 29 | - $this->log->debug( 'Adding names and URIs to existing terms...' ); |
|
| 29 | + $this->log->debug( 'Adding names and URIs to existing terms...' ); |
|
| 30 | 30 | |
| 31 | - $schema_names = array( |
|
| 32 | - 'article' => 'Article', |
|
| 33 | - 'thing' => 'Thing', |
|
| 34 | - 'creative-work' => 'CreativeWork', |
|
| 35 | - 'event' => 'Event', |
|
| 36 | - 'organization' => 'Organization', |
|
| 37 | - 'person' => 'Person', |
|
| 38 | - 'place' => 'Place', |
|
| 39 | - 'localbusiness' => 'LocalBusiness', |
|
| 40 | - 'recipe' => 'Recipe', |
|
| 41 | - 'web-page' => 'WebPage', |
|
| 42 | - 'offer' => 'Offer', |
|
| 43 | - ); |
|
| 31 | + $schema_names = array( |
|
| 32 | + 'article' => 'Article', |
|
| 33 | + 'thing' => 'Thing', |
|
| 34 | + 'creative-work' => 'CreativeWork', |
|
| 35 | + 'event' => 'Event', |
|
| 36 | + 'organization' => 'Organization', |
|
| 37 | + 'person' => 'Person', |
|
| 38 | + 'place' => 'Place', |
|
| 39 | + 'localbusiness' => 'LocalBusiness', |
|
| 40 | + 'recipe' => 'Recipe', |
|
| 41 | + 'web-page' => 'WebPage', |
|
| 42 | + 'offer' => 'Offer', |
|
| 43 | + ); |
|
| 44 | 44 | |
| 45 | - foreach ( $schema_names as $slug => $name ) { |
|
| 46 | - $term = get_term_by( 'slug', $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 45 | + foreach ( $schema_names as $slug => $name ) { |
|
| 46 | + $term = get_term_by( 'slug', $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 47 | 47 | |
| 48 | - if ( false === $term ) { |
|
| 49 | - $this->log->warn( "Term `$slug` not found." ); |
|
| 48 | + if ( false === $term ) { |
|
| 49 | + $this->log->warn( "Term `$slug` not found." ); |
|
| 50 | 50 | |
| 51 | - continue; |
|
| 52 | - } |
|
| 51 | + continue; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - // $this->log->debug( "Adding $name and http://schema.org/$name as name and URI of term `$slug` ({$term->term_id})." ); |
|
| 54 | + // $this->log->debug( "Adding $name and http://schema.org/$name as name and URI of term `$slug` ({$term->term_id})." ); |
|
| 55 | 55 | |
| 56 | - // We don't use the references to the Wordlift_Schemaorg_Class_Service because it might not be |
|
| 57 | - // loaded if the `WL_ALL_ENTITY_TYPES` constant isn't set. |
|
| 58 | - $result_1 = update_term_meta( $term->term_id, '_wl_name', $name ); |
|
| 59 | - $result_2 = update_term_meta( $term->term_id, '_wl_uri', "http://schema.org/$name" ); |
|
| 56 | + // We don't use the references to the Wordlift_Schemaorg_Class_Service because it might not be |
|
| 57 | + // loaded if the `WL_ALL_ENTITY_TYPES` constant isn't set. |
|
| 58 | + $result_1 = update_term_meta( $term->term_id, '_wl_name', $name ); |
|
| 59 | + $result_2 = update_term_meta( $term->term_id, '_wl_uri', "http://schema.org/$name" ); |
|
| 60 | 60 | |
| 61 | - // $this->log->debug( 'name :: ' . var_export( $result_1, true ) . ' URI :: ' . var_export( $result_2, true ) ); |
|
| 61 | + // $this->log->debug( 'name :: ' . var_export( $result_1, true ) . ' URI :: ' . var_export( $result_2, true ) ); |
|
| 62 | 62 | |
| 63 | - } |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - } |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - private function rename_localbusiness_to_local_business() { |
|
| 67 | + private function rename_localbusiness_to_local_business() { |
|
| 68 | 68 | |
| 69 | - $term = get_term_by( 'slug', 'localbusiness', Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 69 | + $term = get_term_by( 'slug', 'localbusiness', Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 70 | 70 | |
| 71 | - if ( false === $term ) { |
|
| 72 | - return; |
|
| 73 | - } |
|
| 71 | + if ( false === $term ) { |
|
| 72 | + return; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - wp_update_term( $term->term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, array( 'slug' => 'local-business' ) ); |
|
| 75 | + wp_update_term( $term->term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, array( 'slug' => 'local-business' ) ); |
|
| 76 | 76 | |
| 77 | - } |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | 79 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | |
| 27 | 27 | private function add_names_to_existing_terms() { |
| 28 | 28 | |
| 29 | - $this->log->debug( 'Adding names and URIs to existing terms...' ); |
|
| 29 | + $this->log->debug('Adding names and URIs to existing terms...'); |
|
| 30 | 30 | |
| 31 | 31 | $schema_names = array( |
| 32 | 32 | 'article' => 'Article', |
@@ -42,11 +42,11 @@ discard block |
||
| 42 | 42 | 'offer' => 'Offer', |
| 43 | 43 | ); |
| 44 | 44 | |
| 45 | - foreach ( $schema_names as $slug => $name ) { |
|
| 46 | - $term = get_term_by( 'slug', $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 45 | + foreach ($schema_names as $slug => $name) { |
|
| 46 | + $term = get_term_by('slug', $slug, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME); |
|
| 47 | 47 | |
| 48 | - if ( false === $term ) { |
|
| 49 | - $this->log->warn( "Term `$slug` not found." ); |
|
| 48 | + if (false === $term) { |
|
| 49 | + $this->log->warn("Term `$slug` not found."); |
|
| 50 | 50 | |
| 51 | 51 | continue; |
| 52 | 52 | } |
@@ -55,8 +55,8 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | // We don't use the references to the Wordlift_Schemaorg_Class_Service because it might not be |
| 57 | 57 | // loaded if the `WL_ALL_ENTITY_TYPES` constant isn't set. |
| 58 | - $result_1 = update_term_meta( $term->term_id, '_wl_name', $name ); |
|
| 59 | - $result_2 = update_term_meta( $term->term_id, '_wl_uri', "http://schema.org/$name" ); |
|
| 58 | + $result_1 = update_term_meta($term->term_id, '_wl_name', $name); |
|
| 59 | + $result_2 = update_term_meta($term->term_id, '_wl_uri', "http://schema.org/$name"); |
|
| 60 | 60 | |
| 61 | 61 | // $this->log->debug( 'name :: ' . var_export( $result_1, true ) . ' URI :: ' . var_export( $result_2, true ) ); |
| 62 | 62 | |
@@ -66,13 +66,13 @@ discard block |
||
| 66 | 66 | |
| 67 | 67 | private function rename_localbusiness_to_local_business() { |
| 68 | 68 | |
| 69 | - $term = get_term_by( 'slug', 'localbusiness', Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 69 | + $term = get_term_by('slug', 'localbusiness', Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME); |
|
| 70 | 70 | |
| 71 | - if ( false === $term ) { |
|
| 71 | + if (false === $term) { |
|
| 72 | 72 | return; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - wp_update_term( $term->term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, array( 'slug' => 'local-business' ) ); |
|
| 75 | + wp_update_term($term->term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, array('slug' => 'local-business')); |
|
| 76 | 76 | |
| 77 | 77 | } |
| 78 | 78 | |
@@ -19,85 +19,85 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class Wordlift_Image_Service { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * The image ratios and sizes. |
|
| 24 | - * |
|
| 25 | - * @since 3.19.4 |
|
| 26 | - * @access public |
|
| 27 | - * @var array $sizes The image ratios and sizes. |
|
| 28 | - */ |
|
| 29 | - public static $sizes = array( |
|
| 30 | - '16x9' => array( 1200, 675 ), |
|
| 31 | - '4x3' => array( 1200, 900 ), |
|
| 32 | - '1x1' => array( 1200, 1200 ), |
|
| 33 | - ); |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Create a {@link Wordlift_Image_Service} instance. |
|
| 37 | - * |
|
| 38 | - * @since 3.19.4 |
|
| 39 | - */ |
|
| 40 | - public function __construct() { |
|
| 41 | - |
|
| 42 | - // Add hook to define the image sizes. Since we're a plugin, we cannot use the |
|
| 43 | - // `after_theme_setup` hook. |
|
| 44 | - add_action( 'init', array( $this, 'after_theme_setup' ) ); |
|
| 45 | - |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Hook `after_theme_setup`: add our own image sizes. |
|
| 50 | - * |
|
| 51 | - * @since 3.19.4 |
|
| 52 | - */ |
|
| 53 | - public function after_theme_setup() { |
|
| 54 | - |
|
| 55 | - foreach ( self::$sizes as $ratio => $sizes ) { |
|
| 56 | - add_image_size( "wl-$ratio", $sizes[0], $sizes[1], true ); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Get the sources for the specified attachment. |
|
| 63 | - * |
|
| 64 | - * @since 3.19.4 |
|
| 65 | - * |
|
| 66 | - * @param int $attachment_id The attachment id. |
|
| 67 | - * |
|
| 68 | - * @return array { |
|
| 69 | - * An array of image sources. |
|
| 70 | - * |
|
| 71 | - * @type string $url The attachment URL. |
|
| 72 | - * @type int $width The attachment width. |
|
| 73 | - * @type int $height The attachment height. |
|
| 74 | - * } |
|
| 75 | - */ |
|
| 76 | - public static function get_sources( $attachment_id ) { |
|
| 77 | - |
|
| 78 | - // Get the source for the specified image sizes. |
|
| 79 | - $sources = array_map( function ( $ratio ) use ( $attachment_id ) { |
|
| 80 | - |
|
| 81 | - // Get the source of the specified ratio. |
|
| 82 | - $source = wp_get_attachment_image_src( $attachment_id, "wl-$ratio" ); |
|
| 83 | - |
|
| 84 | - // Get the size for the specified ratio. |
|
| 85 | - $size = Wordlift_Image_Service::$sizes[ $ratio ]; |
|
| 86 | - |
|
| 87 | - // Check that the source has an image, and the required size. |
|
| 88 | - if ( empty( $source[0] ) || $size[0] !== $source[1] || $size[1] !== $source[2] ) { |
|
| 89 | - return null; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // Return the source. |
|
| 93 | - return $source; |
|
| 94 | - }, array_keys( self::$sizes ) ); |
|
| 95 | - |
|
| 96 | - // Filter unavailable sources. |
|
| 97 | - $sources_1200 = array_filter( $sources ); |
|
| 98 | - |
|
| 99 | - // Make the results unique. |
|
| 100 | - return $sources_1200; |
|
| 101 | - } |
|
| 22 | + /** |
|
| 23 | + * The image ratios and sizes. |
|
| 24 | + * |
|
| 25 | + * @since 3.19.4 |
|
| 26 | + * @access public |
|
| 27 | + * @var array $sizes The image ratios and sizes. |
|
| 28 | + */ |
|
| 29 | + public static $sizes = array( |
|
| 30 | + '16x9' => array( 1200, 675 ), |
|
| 31 | + '4x3' => array( 1200, 900 ), |
|
| 32 | + '1x1' => array( 1200, 1200 ), |
|
| 33 | + ); |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Create a {@link Wordlift_Image_Service} instance. |
|
| 37 | + * |
|
| 38 | + * @since 3.19.4 |
|
| 39 | + */ |
|
| 40 | + public function __construct() { |
|
| 41 | + |
|
| 42 | + // Add hook to define the image sizes. Since we're a plugin, we cannot use the |
|
| 43 | + // `after_theme_setup` hook. |
|
| 44 | + add_action( 'init', array( $this, 'after_theme_setup' ) ); |
|
| 45 | + |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Hook `after_theme_setup`: add our own image sizes. |
|
| 50 | + * |
|
| 51 | + * @since 3.19.4 |
|
| 52 | + */ |
|
| 53 | + public function after_theme_setup() { |
|
| 54 | + |
|
| 55 | + foreach ( self::$sizes as $ratio => $sizes ) { |
|
| 56 | + add_image_size( "wl-$ratio", $sizes[0], $sizes[1], true ); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Get the sources for the specified attachment. |
|
| 63 | + * |
|
| 64 | + * @since 3.19.4 |
|
| 65 | + * |
|
| 66 | + * @param int $attachment_id The attachment id. |
|
| 67 | + * |
|
| 68 | + * @return array { |
|
| 69 | + * An array of image sources. |
|
| 70 | + * |
|
| 71 | + * @type string $url The attachment URL. |
|
| 72 | + * @type int $width The attachment width. |
|
| 73 | + * @type int $height The attachment height. |
|
| 74 | + * } |
|
| 75 | + */ |
|
| 76 | + public static function get_sources( $attachment_id ) { |
|
| 77 | + |
|
| 78 | + // Get the source for the specified image sizes. |
|
| 79 | + $sources = array_map( function ( $ratio ) use ( $attachment_id ) { |
|
| 80 | + |
|
| 81 | + // Get the source of the specified ratio. |
|
| 82 | + $source = wp_get_attachment_image_src( $attachment_id, "wl-$ratio" ); |
|
| 83 | + |
|
| 84 | + // Get the size for the specified ratio. |
|
| 85 | + $size = Wordlift_Image_Service::$sizes[ $ratio ]; |
|
| 86 | + |
|
| 87 | + // Check that the source has an image, and the required size. |
|
| 88 | + if ( empty( $source[0] ) || $size[0] !== $source[1] || $size[1] !== $source[2] ) { |
|
| 89 | + return null; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // Return the source. |
|
| 93 | + return $source; |
|
| 94 | + }, array_keys( self::$sizes ) ); |
|
| 95 | + |
|
| 96 | + // Filter unavailable sources. |
|
| 97 | + $sources_1200 = array_filter( $sources ); |
|
| 98 | + |
|
| 99 | + // Make the results unique. |
|
| 100 | + return $sources_1200; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | 103 | } |
@@ -27,9 +27,9 @@ discard block |
||
| 27 | 27 | * @var array $sizes The image ratios and sizes. |
| 28 | 28 | */ |
| 29 | 29 | public static $sizes = array( |
| 30 | - '16x9' => array( 1200, 675 ), |
|
| 31 | - '4x3' => array( 1200, 900 ), |
|
| 32 | - '1x1' => array( 1200, 1200 ), |
|
| 30 | + '16x9' => array(1200, 675), |
|
| 31 | + '4x3' => array(1200, 900), |
|
| 32 | + '1x1' => array(1200, 1200), |
|
| 33 | 33 | ); |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | |
| 42 | 42 | // Add hook to define the image sizes. Since we're a plugin, we cannot use the |
| 43 | 43 | // `after_theme_setup` hook. |
| 44 | - add_action( 'init', array( $this, 'after_theme_setup' ) ); |
|
| 44 | + add_action('init', array($this, 'after_theme_setup')); |
|
| 45 | 45 | |
| 46 | 46 | } |
| 47 | 47 | |
@@ -52,8 +52,8 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | public function after_theme_setup() { |
| 54 | 54 | |
| 55 | - foreach ( self::$sizes as $ratio => $sizes ) { |
|
| 56 | - add_image_size( "wl-$ratio", $sizes[0], $sizes[1], true ); |
|
| 55 | + foreach (self::$sizes as $ratio => $sizes) { |
|
| 56 | + add_image_size("wl-$ratio", $sizes[0], $sizes[1], true); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | } |
@@ -73,28 +73,28 @@ discard block |
||
| 73 | 73 | * @type int $height The attachment height. |
| 74 | 74 | * } |
| 75 | 75 | */ |
| 76 | - public static function get_sources( $attachment_id ) { |
|
| 76 | + public static function get_sources($attachment_id) { |
|
| 77 | 77 | |
| 78 | 78 | // Get the source for the specified image sizes. |
| 79 | - $sources = array_map( function ( $ratio ) use ( $attachment_id ) { |
|
| 79 | + $sources = array_map(function($ratio) use ($attachment_id) { |
|
| 80 | 80 | |
| 81 | 81 | // Get the source of the specified ratio. |
| 82 | - $source = wp_get_attachment_image_src( $attachment_id, "wl-$ratio" ); |
|
| 82 | + $source = wp_get_attachment_image_src($attachment_id, "wl-$ratio"); |
|
| 83 | 83 | |
| 84 | 84 | // Get the size for the specified ratio. |
| 85 | - $size = Wordlift_Image_Service::$sizes[ $ratio ]; |
|
| 85 | + $size = Wordlift_Image_Service::$sizes[$ratio]; |
|
| 86 | 86 | |
| 87 | 87 | // Check that the source has an image, and the required size. |
| 88 | - if ( empty( $source[0] ) || $size[0] !== $source[1] || $size[1] !== $source[2] ) { |
|
| 88 | + if (empty($source[0]) || $size[0] !== $source[1] || $size[1] !== $source[2]) { |
|
| 89 | 89 | return null; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | // Return the source. |
| 93 | 93 | return $source; |
| 94 | - }, array_keys( self::$sizes ) ); |
|
| 94 | + }, array_keys(self::$sizes)); |
|
| 95 | 95 | |
| 96 | 96 | // Filter unavailable sources. |
| 97 | - $sources_1200 = array_filter( $sources ); |
|
| 97 | + $sources_1200 = array_filter($sources); |
|
| 98 | 98 | |
| 99 | 99 | // Make the results unique. |
| 100 | 100 | return $sources_1200; |
@@ -16,23 +16,23 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Wordlift_Install_3_19_5 extends Wordlift_Install { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * {@inheritdoc} |
|
| 21 | - */ |
|
| 22 | - protected static $version = '3.19.5'; |
|
| 19 | + /** |
|
| 20 | + * {@inheritdoc} |
|
| 21 | + */ |
|
| 22 | + protected static $version = '3.19.5'; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * {@inheritdoc} |
|
| 26 | - */ |
|
| 27 | - public function install() { |
|
| 24 | + /** |
|
| 25 | + * {@inheritdoc} |
|
| 26 | + */ |
|
| 27 | + public function install() { |
|
| 28 | 28 | |
| 29 | - /* |
|
| 29 | + /* |
|
| 30 | 30 | * Flush all the caches, since we changed some JSON-LD publishing rules. |
| 31 | 31 | * |
| 32 | 32 | * @see https://github.com/insideout10/wordlift-plugin/issues/858 |
| 33 | 33 | */ |
| 34 | - Wordlift_File_Cache_Service::flush_all(); |
|
| 34 | + Wordlift_File_Cache_Service::flush_all(); |
|
| 35 | 35 | |
| 36 | - } |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | } |
@@ -18,11 +18,11 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Admin_Language_Select_Element extends Wordlift_Admin_Select_Element { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @inheritdoc |
|
| 23 | - */ |
|
| 24 | - public function render_options( $params ) { |
|
| 25 | - /* |
|
| 21 | + /** |
|
| 22 | + * @inheritdoc |
|
| 23 | + */ |
|
| 24 | + public function render_options( $params ) { |
|
| 25 | + /* |
|
| 26 | 26 | * Print all the supported language, preselecting the one configured |
| 27 | 27 | * in WP (or English if not supported). We now use the `Wordlift_Languages` |
| 28 | 28 | * class which provides the list of languages supported by WordLift. |
@@ -30,14 +30,14 @@ discard block |
||
| 30 | 30 | * See https://github.com/insideout10/wordlift-plugin/issues/349 |
| 31 | 31 | */ |
| 32 | 32 | |
| 33 | - // Get WordLift's supported languages. |
|
| 34 | - $languages = Wordlift_Languages::get_languages(); |
|
| 33 | + // Get WordLift's supported languages. |
|
| 34 | + $languages = Wordlift_Languages::get_languages(); |
|
| 35 | 35 | |
| 36 | - // If we support WP's configured language, then use that, otherwise use English by default. |
|
| 37 | - $language = isset( $languages[ $params['value'] ] ) ? $params['value'] : 'en'; |
|
| 36 | + // If we support WP's configured language, then use that, otherwise use English by default. |
|
| 37 | + $language = isset( $languages[ $params['value'] ] ) ? $params['value'] : 'en'; |
|
| 38 | 38 | |
| 39 | - foreach ( $languages as $code => $label ) : |
|
| 40 | - ?> |
|
| 39 | + foreach ( $languages as $code => $label ) : |
|
| 40 | + ?> |
|
| 41 | 41 | <option |
| 42 | 42 | value="<?php echo esc_attr( $code ); ?>" |
| 43 | 43 | <?php echo selected( $code, $language, false ); ?> |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | <?php echo esc_html( $label ); ?> |
| 46 | 46 | </option> |
| 47 | 47 | <?php |
| 48 | - endforeach; |
|
| 49 | - } |
|
| 48 | + endforeach; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | 51 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | /** |
| 22 | 22 | * @inheritdoc |
| 23 | 23 | */ |
| 24 | - public function render_options( $params ) { |
|
| 24 | + public function render_options($params) { |
|
| 25 | 25 | /* |
| 26 | 26 | * Print all the supported language, preselecting the one configured |
| 27 | 27 | * in WP (or English if not supported). We now use the `Wordlift_Languages` |
@@ -34,15 +34,15 @@ discard block |
||
| 34 | 34 | $languages = Wordlift_Languages::get_languages(); |
| 35 | 35 | |
| 36 | 36 | // If we support WP's configured language, then use that, otherwise use English by default. |
| 37 | - $language = isset( $languages[ $params['value'] ] ) ? $params['value'] : 'en'; |
|
| 37 | + $language = isset($languages[$params['value']]) ? $params['value'] : 'en'; |
|
| 38 | 38 | |
| 39 | - foreach ( $languages as $code => $label ) : |
|
| 39 | + foreach ($languages as $code => $label) : |
|
| 40 | 40 | ?> |
| 41 | 41 | <option |
| 42 | - value="<?php echo esc_attr( $code ); ?>" |
|
| 43 | - <?php echo selected( $code, $language, false ); ?> |
|
| 42 | + value="<?php echo esc_attr($code); ?>" |
|
| 43 | + <?php echo selected($code, $language, false); ?> |
|
| 44 | 44 | > |
| 45 | - <?php echo esc_html( $label ); ?> |
|
| 45 | + <?php echo esc_html($label); ?> |
|
| 46 | 46 | </option> |
| 47 | 47 | <?php |
| 48 | 48 | endforeach; |
@@ -19,118 +19,118 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class Wordlift_Admin_Author_Element implements Wordlift_Admin_Element { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * The {@link Wordlift_Publisher_Service} instance. |
|
| 24 | - * |
|
| 25 | - * @since 3.14.0 |
|
| 26 | - * @access private |
|
| 27 | - * @var \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance. |
|
| 28 | - */ |
|
| 29 | - private $publisher_service; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * A {@link Wordlift_Admin_Select2_Element} instance. |
|
| 33 | - * |
|
| 34 | - * @since 3.14.0 |
|
| 35 | - * @access private |
|
| 36 | - * @var \Wordlift_Admin_Select2_Element $select_element A {@link Wordlift_Admin_Select2_Element} instance. |
|
| 37 | - */ |
|
| 38 | - private $select_element; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Create a {@link Wordlift_Admin_Person_Element} instance. |
|
| 42 | - * |
|
| 43 | - * @since 3.14.0 |
|
| 44 | - * |
|
| 45 | - * @param \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance. |
|
| 46 | - * @param \Wordlift_Admin_Select2_Element $select_element The {@link Wordlift_Admin_Select_Element} instance. |
|
| 47 | - */ |
|
| 48 | - function __construct( $publisher_service, $select_element ) { |
|
| 49 | - |
|
| 50 | - $this->publisher_service = $publisher_service; |
|
| 51 | - |
|
| 52 | - // Child elements. |
|
| 53 | - $this->select_element = $select_element; |
|
| 54 | - |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @inheritdoc |
|
| 59 | - */ |
|
| 60 | - public function render( $args ) { |
|
| 61 | - |
|
| 62 | - // Parse the arguments and merge with default values. |
|
| 63 | - $params = wp_parse_args( $args, array( |
|
| 64 | - 'id' => uniqid( 'wl-input-' ), |
|
| 65 | - 'name' => uniqid( 'wl-input-' ), |
|
| 66 | - 'current_entity' => 0, |
|
| 67 | - ) ); |
|
| 68 | - |
|
| 69 | - $current_entity_id = $params['current_entity']; |
|
| 70 | - $data = $this->publisher_service->query(); |
|
| 71 | - |
|
| 72 | - // Set a default to show when no entity is associated and a way to unassign. |
|
| 73 | - array_unshift( $data, array( |
|
| 74 | - 'id' => '0', |
|
| 75 | - 'text' => __( '<em>(none)</em>', 'wordlift' ), |
|
| 76 | - 'type' => '', |
|
| 77 | - 'thumbnail_url' => plugin_dir_url( dirname( __FILE__ ) ) . 'images/pixel.png', |
|
| 78 | - ) ); |
|
| 79 | - |
|
| 80 | - // Finally do the render, passing along also the current selected entity |
|
| 81 | - // id and the options data. |
|
| 82 | - return $this->do_render( $params, $current_entity_id, $data ); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Render the `select` using the provided parameters. |
|
| 87 | - * |
|
| 88 | - * @since 3.14.0 |
|
| 89 | - * |
|
| 90 | - * @param array $params The array of parameters from the `render` function. |
|
| 91 | - * @param int $current_post_id The currently selected {@link WP_Post} `id`. |
|
| 92 | - * @param array $data An array of Select2 options. |
|
| 93 | - * |
|
| 94 | - * @return \Wordlift_Admin_Author_Element $this Return this element. |
|
| 95 | - */ |
|
| 96 | - protected function do_render( $params, $current_post_id, $data ) { |
|
| 97 | - |
|
| 98 | - // Queue the script which will initialize the select and style it. |
|
| 99 | - wp_enqueue_script( 'wl-author-element', plugin_dir_url( dirname( __FILE__ ) ) . 'js/1/author.js', array( 'wordlift-select2' ) ); |
|
| 100 | - wp_enqueue_style( 'wl-author-element', plugin_dir_url( dirname( __FILE__ ) ) . 'js/1/author.css' ); |
|
| 101 | - |
|
| 102 | - // Prepare the URLs for entities which don't have logos. |
|
| 103 | - $person_thumbnail_url = plugin_dir_url( dirname( __FILE__ ) ) . '../images/person.png'; |
|
| 104 | - $organization_thumbnail_url = plugin_dir_url( dirname( __FILE__ ) ) . '../images/organization.png'; |
|
| 105 | - |
|
| 106 | - // Get the current post. |
|
| 107 | - $current_post = $current_post_id ? get_post( $current_post_id ) : null; |
|
| 108 | - |
|
| 109 | - // Finally render the Select. |
|
| 110 | - $this->select_element->render( array( |
|
| 111 | - // Id. |
|
| 112 | - 'id' => $params['id'], |
|
| 113 | - // Name. |
|
| 114 | - 'name' => $params['name'], |
|
| 115 | - // Class names. |
|
| 116 | - 'class' => 'wl-select2-element', |
|
| 117 | - // The selected id. |
|
| 118 | - 'value' => $current_post_id, |
|
| 119 | - // The selected item (must be in the options for Select2 to display it). |
|
| 120 | - 'options' => $current_post ? array( $current_post->ID => $current_post->post_title ) : array(), |
|
| 121 | - // Data attributes. |
|
| 122 | - 'data' => array( |
|
| 123 | - // The list of available options. |
|
| 124 | - 'wl-select2-data' => json_encode( $data ), |
|
| 125 | - // The HTML template for each option. |
|
| 126 | - 'wl-select2-template-result' => "<div class='wl-select2-result'><span class='wl-select2-thumbnail' style='background-image: url( <%= obj.thumbnail_url || ( 'Organization' === obj.type ? '$organization_thumbnail_url' : '$person_thumbnail_url' ) %> );'> </span><span class='wl-select2'><%= obj.text %></span><span class='wl-select2-type'><%= obj.type %></span></div>", |
|
| 127 | - // The HTML template for the selected option. |
|
| 128 | - 'wl-select2-template-selection' => "<div class='wl-select2-selection'><span class='wl-select2-thumbnail' style='background-image: url( <%= obj.thumbnail_url || ( 'Organization' === obj.type ? '$organization_thumbnail_url' : '$person_thumbnail_url' ) %> );'> </span><span class='wl-select2'><%= obj.text %></span><span class='wl-select2-type'><%= obj.type %></span></div>", |
|
| 129 | - ), |
|
| 130 | - ) ); |
|
| 131 | - |
|
| 132 | - // Finally return the element instance. |
|
| 133 | - return $this; |
|
| 134 | - } |
|
| 22 | + /** |
|
| 23 | + * The {@link Wordlift_Publisher_Service} instance. |
|
| 24 | + * |
|
| 25 | + * @since 3.14.0 |
|
| 26 | + * @access private |
|
| 27 | + * @var \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance. |
|
| 28 | + */ |
|
| 29 | + private $publisher_service; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * A {@link Wordlift_Admin_Select2_Element} instance. |
|
| 33 | + * |
|
| 34 | + * @since 3.14.0 |
|
| 35 | + * @access private |
|
| 36 | + * @var \Wordlift_Admin_Select2_Element $select_element A {@link Wordlift_Admin_Select2_Element} instance. |
|
| 37 | + */ |
|
| 38 | + private $select_element; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Create a {@link Wordlift_Admin_Person_Element} instance. |
|
| 42 | + * |
|
| 43 | + * @since 3.14.0 |
|
| 44 | + * |
|
| 45 | + * @param \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance. |
|
| 46 | + * @param \Wordlift_Admin_Select2_Element $select_element The {@link Wordlift_Admin_Select_Element} instance. |
|
| 47 | + */ |
|
| 48 | + function __construct( $publisher_service, $select_element ) { |
|
| 49 | + |
|
| 50 | + $this->publisher_service = $publisher_service; |
|
| 51 | + |
|
| 52 | + // Child elements. |
|
| 53 | + $this->select_element = $select_element; |
|
| 54 | + |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @inheritdoc |
|
| 59 | + */ |
|
| 60 | + public function render( $args ) { |
|
| 61 | + |
|
| 62 | + // Parse the arguments and merge with default values. |
|
| 63 | + $params = wp_parse_args( $args, array( |
|
| 64 | + 'id' => uniqid( 'wl-input-' ), |
|
| 65 | + 'name' => uniqid( 'wl-input-' ), |
|
| 66 | + 'current_entity' => 0, |
|
| 67 | + ) ); |
|
| 68 | + |
|
| 69 | + $current_entity_id = $params['current_entity']; |
|
| 70 | + $data = $this->publisher_service->query(); |
|
| 71 | + |
|
| 72 | + // Set a default to show when no entity is associated and a way to unassign. |
|
| 73 | + array_unshift( $data, array( |
|
| 74 | + 'id' => '0', |
|
| 75 | + 'text' => __( '<em>(none)</em>', 'wordlift' ), |
|
| 76 | + 'type' => '', |
|
| 77 | + 'thumbnail_url' => plugin_dir_url( dirname( __FILE__ ) ) . 'images/pixel.png', |
|
| 78 | + ) ); |
|
| 79 | + |
|
| 80 | + // Finally do the render, passing along also the current selected entity |
|
| 81 | + // id and the options data. |
|
| 82 | + return $this->do_render( $params, $current_entity_id, $data ); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Render the `select` using the provided parameters. |
|
| 87 | + * |
|
| 88 | + * @since 3.14.0 |
|
| 89 | + * |
|
| 90 | + * @param array $params The array of parameters from the `render` function. |
|
| 91 | + * @param int $current_post_id The currently selected {@link WP_Post} `id`. |
|
| 92 | + * @param array $data An array of Select2 options. |
|
| 93 | + * |
|
| 94 | + * @return \Wordlift_Admin_Author_Element $this Return this element. |
|
| 95 | + */ |
|
| 96 | + protected function do_render( $params, $current_post_id, $data ) { |
|
| 97 | + |
|
| 98 | + // Queue the script which will initialize the select and style it. |
|
| 99 | + wp_enqueue_script( 'wl-author-element', plugin_dir_url( dirname( __FILE__ ) ) . 'js/1/author.js', array( 'wordlift-select2' ) ); |
|
| 100 | + wp_enqueue_style( 'wl-author-element', plugin_dir_url( dirname( __FILE__ ) ) . 'js/1/author.css' ); |
|
| 101 | + |
|
| 102 | + // Prepare the URLs for entities which don't have logos. |
|
| 103 | + $person_thumbnail_url = plugin_dir_url( dirname( __FILE__ ) ) . '../images/person.png'; |
|
| 104 | + $organization_thumbnail_url = plugin_dir_url( dirname( __FILE__ ) ) . '../images/organization.png'; |
|
| 105 | + |
|
| 106 | + // Get the current post. |
|
| 107 | + $current_post = $current_post_id ? get_post( $current_post_id ) : null; |
|
| 108 | + |
|
| 109 | + // Finally render the Select. |
|
| 110 | + $this->select_element->render( array( |
|
| 111 | + // Id. |
|
| 112 | + 'id' => $params['id'], |
|
| 113 | + // Name. |
|
| 114 | + 'name' => $params['name'], |
|
| 115 | + // Class names. |
|
| 116 | + 'class' => 'wl-select2-element', |
|
| 117 | + // The selected id. |
|
| 118 | + 'value' => $current_post_id, |
|
| 119 | + // The selected item (must be in the options for Select2 to display it). |
|
| 120 | + 'options' => $current_post ? array( $current_post->ID => $current_post->post_title ) : array(), |
|
| 121 | + // Data attributes. |
|
| 122 | + 'data' => array( |
|
| 123 | + // The list of available options. |
|
| 124 | + 'wl-select2-data' => json_encode( $data ), |
|
| 125 | + // The HTML template for each option. |
|
| 126 | + 'wl-select2-template-result' => "<div class='wl-select2-result'><span class='wl-select2-thumbnail' style='background-image: url( <%= obj.thumbnail_url || ( 'Organization' === obj.type ? '$organization_thumbnail_url' : '$person_thumbnail_url' ) %> );'> </span><span class='wl-select2'><%= obj.text %></span><span class='wl-select2-type'><%= obj.type %></span></div>", |
|
| 127 | + // The HTML template for the selected option. |
|
| 128 | + 'wl-select2-template-selection' => "<div class='wl-select2-selection'><span class='wl-select2-thumbnail' style='background-image: url( <%= obj.thumbnail_url || ( 'Organization' === obj.type ? '$organization_thumbnail_url' : '$person_thumbnail_url' ) %> );'> </span><span class='wl-select2'><%= obj.text %></span><span class='wl-select2-type'><%= obj.type %></span></div>", |
|
| 129 | + ), |
|
| 130 | + ) ); |
|
| 131 | + |
|
| 132 | + // Finally return the element instance. |
|
| 133 | + return $this; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | 136 | } |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * @param \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance. |
| 46 | 46 | * @param \Wordlift_Admin_Select2_Element $select_element The {@link Wordlift_Admin_Select_Element} instance. |
| 47 | 47 | */ |
| 48 | - function __construct( $publisher_service, $select_element ) { |
|
| 48 | + function __construct($publisher_service, $select_element) { |
|
| 49 | 49 | |
| 50 | 50 | $this->publisher_service = $publisher_service; |
| 51 | 51 | |
@@ -57,29 +57,29 @@ discard block |
||
| 57 | 57 | /** |
| 58 | 58 | * @inheritdoc |
| 59 | 59 | */ |
| 60 | - public function render( $args ) { |
|
| 60 | + public function render($args) { |
|
| 61 | 61 | |
| 62 | 62 | // Parse the arguments and merge with default values. |
| 63 | - $params = wp_parse_args( $args, array( |
|
| 64 | - 'id' => uniqid( 'wl-input-' ), |
|
| 65 | - 'name' => uniqid( 'wl-input-' ), |
|
| 63 | + $params = wp_parse_args($args, array( |
|
| 64 | + 'id' => uniqid('wl-input-'), |
|
| 65 | + 'name' => uniqid('wl-input-'), |
|
| 66 | 66 | 'current_entity' => 0, |
| 67 | - ) ); |
|
| 67 | + )); |
|
| 68 | 68 | |
| 69 | 69 | $current_entity_id = $params['current_entity']; |
| 70 | 70 | $data = $this->publisher_service->query(); |
| 71 | 71 | |
| 72 | 72 | // Set a default to show when no entity is associated and a way to unassign. |
| 73 | - array_unshift( $data, array( |
|
| 73 | + array_unshift($data, array( |
|
| 74 | 74 | 'id' => '0', |
| 75 | - 'text' => __( '<em>(none)</em>', 'wordlift' ), |
|
| 75 | + 'text' => __('<em>(none)</em>', 'wordlift'), |
|
| 76 | 76 | 'type' => '', |
| 77 | - 'thumbnail_url' => plugin_dir_url( dirname( __FILE__ ) ) . 'images/pixel.png', |
|
| 78 | - ) ); |
|
| 77 | + 'thumbnail_url' => plugin_dir_url(dirname(__FILE__)).'images/pixel.png', |
|
| 78 | + )); |
|
| 79 | 79 | |
| 80 | 80 | // Finally do the render, passing along also the current selected entity |
| 81 | 81 | // id and the options data. |
| 82 | - return $this->do_render( $params, $current_entity_id, $data ); |
|
| 82 | + return $this->do_render($params, $current_entity_id, $data); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -93,21 +93,21 @@ discard block |
||
| 93 | 93 | * |
| 94 | 94 | * @return \Wordlift_Admin_Author_Element $this Return this element. |
| 95 | 95 | */ |
| 96 | - protected function do_render( $params, $current_post_id, $data ) { |
|
| 96 | + protected function do_render($params, $current_post_id, $data) { |
|
| 97 | 97 | |
| 98 | 98 | // Queue the script which will initialize the select and style it. |
| 99 | - wp_enqueue_script( 'wl-author-element', plugin_dir_url( dirname( __FILE__ ) ) . 'js/1/author.js', array( 'wordlift-select2' ) ); |
|
| 100 | - wp_enqueue_style( 'wl-author-element', plugin_dir_url( dirname( __FILE__ ) ) . 'js/1/author.css' ); |
|
| 99 | + wp_enqueue_script('wl-author-element', plugin_dir_url(dirname(__FILE__)).'js/1/author.js', array('wordlift-select2')); |
|
| 100 | + wp_enqueue_style('wl-author-element', plugin_dir_url(dirname(__FILE__)).'js/1/author.css'); |
|
| 101 | 101 | |
| 102 | 102 | // Prepare the URLs for entities which don't have logos. |
| 103 | - $person_thumbnail_url = plugin_dir_url( dirname( __FILE__ ) ) . '../images/person.png'; |
|
| 104 | - $organization_thumbnail_url = plugin_dir_url( dirname( __FILE__ ) ) . '../images/organization.png'; |
|
| 103 | + $person_thumbnail_url = plugin_dir_url(dirname(__FILE__)).'../images/person.png'; |
|
| 104 | + $organization_thumbnail_url = plugin_dir_url(dirname(__FILE__)).'../images/organization.png'; |
|
| 105 | 105 | |
| 106 | 106 | // Get the current post. |
| 107 | - $current_post = $current_post_id ? get_post( $current_post_id ) : null; |
|
| 107 | + $current_post = $current_post_id ? get_post($current_post_id) : null; |
|
| 108 | 108 | |
| 109 | 109 | // Finally render the Select. |
| 110 | - $this->select_element->render( array( |
|
| 110 | + $this->select_element->render(array( |
|
| 111 | 111 | // Id. |
| 112 | 112 | 'id' => $params['id'], |
| 113 | 113 | // Name. |
@@ -117,17 +117,17 @@ discard block |
||
| 117 | 117 | // The selected id. |
| 118 | 118 | 'value' => $current_post_id, |
| 119 | 119 | // The selected item (must be in the options for Select2 to display it). |
| 120 | - 'options' => $current_post ? array( $current_post->ID => $current_post->post_title ) : array(), |
|
| 120 | + 'options' => $current_post ? array($current_post->ID => $current_post->post_title) : array(), |
|
| 121 | 121 | // Data attributes. |
| 122 | 122 | 'data' => array( |
| 123 | 123 | // The list of available options. |
| 124 | - 'wl-select2-data' => json_encode( $data ), |
|
| 124 | + 'wl-select2-data' => json_encode($data), |
|
| 125 | 125 | // The HTML template for each option. |
| 126 | 126 | 'wl-select2-template-result' => "<div class='wl-select2-result'><span class='wl-select2-thumbnail' style='background-image: url( <%= obj.thumbnail_url || ( 'Organization' === obj.type ? '$organization_thumbnail_url' : '$person_thumbnail_url' ) %> );'> </span><span class='wl-select2'><%= obj.text %></span><span class='wl-select2-type'><%= obj.type %></span></div>", |
| 127 | 127 | // The HTML template for the selected option. |
| 128 | 128 | 'wl-select2-template-selection' => "<div class='wl-select2-selection'><span class='wl-select2-thumbnail' style='background-image: url( <%= obj.thumbnail_url || ( 'Organization' === obj.type ? '$organization_thumbnail_url' : '$person_thumbnail_url' ) %> );'> </span><span class='wl-select2'><%= obj.text %></span><span class='wl-select2-type'><%= obj.type %></span></div>", |
| 129 | 129 | ), |
| 130 | - ) ); |
|
| 130 | + )); |
|
| 131 | 131 | |
| 132 | 132 | // Finally return the element instance. |
| 133 | 133 | return $this; |
@@ -18,38 +18,38 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Admin_Country_Select_Element extends Wordlift_Admin_Select_Element { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Adds a filter that will add data `country-codes` attrbiute to the country select |
|
| 23 | - * to allow front-end validation. |
|
| 24 | - * |
|
| 25 | - * @since 3.18.0 |
|
| 26 | - * |
|
| 27 | - */ |
|
| 28 | - public function __construct() { |
|
| 29 | - // Adds the country codes as data attribute to allow front-end validation. |
|
| 30 | - add_filter( 'wl_admin_select_element_data_attributes', array( $this, 'add_country_codes_data' ), 10, 1 ); |
|
| 31 | - } |
|
| 21 | + /** |
|
| 22 | + * Adds a filter that will add data `country-codes` attrbiute to the country select |
|
| 23 | + * to allow front-end validation. |
|
| 24 | + * |
|
| 25 | + * @since 3.18.0 |
|
| 26 | + * |
|
| 27 | + */ |
|
| 28 | + public function __construct() { |
|
| 29 | + // Adds the country codes as data attribute to allow front-end validation. |
|
| 30 | + add_filter( 'wl_admin_select_element_data_attributes', array( $this, 'add_country_codes_data' ), 10, 1 ); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @inheritdoc |
|
| 35 | - */ |
|
| 36 | - public function render_options( $params ) { |
|
| 37 | - // Print all the supported countries, preselecting the one configured |
|
| 38 | - // in WP (or United Kingdom if not supported). We now use the `Wordlift_Countries` |
|
| 39 | - // class which provides the list of countries supported by WordLift. |
|
| 40 | - // |
|
| 41 | - // https://github.com/insideout10/wordlift-plugin/issues/713 |
|
| 33 | + /** |
|
| 34 | + * @inheritdoc |
|
| 35 | + */ |
|
| 36 | + public function render_options( $params ) { |
|
| 37 | + // Print all the supported countries, preselecting the one configured |
|
| 38 | + // in WP (or United Kingdom if not supported). We now use the `Wordlift_Countries` |
|
| 39 | + // class which provides the list of countries supported by WordLift. |
|
| 40 | + // |
|
| 41 | + // https://github.com/insideout10/wordlift-plugin/issues/713 |
|
| 42 | 42 | |
| 43 | - $lang = ( isset( $params['lang'] ) ) ? $params['lang'] : false; |
|
| 43 | + $lang = ( isset( $params['lang'] ) ) ? $params['lang'] : false; |
|
| 44 | 44 | |
| 45 | - // Get WordLift's supported countries. |
|
| 46 | - $countries = Wordlift_Countries::get_countries( $lang ); |
|
| 45 | + // Get WordLift's supported countries. |
|
| 46 | + $countries = Wordlift_Countries::get_countries( $lang ); |
|
| 47 | 47 | |
| 48 | - // If we support WP's configured language, then use that, otherwise use English by default. |
|
| 49 | - $language = isset( $countries[ $params['value'] ] ) ? $params['value'] : 'uk'; |
|
| 48 | + // If we support WP's configured language, then use that, otherwise use English by default. |
|
| 49 | + $language = isset( $countries[ $params['value'] ] ) ? $params['value'] : 'uk'; |
|
| 50 | 50 | |
| 51 | - foreach ( $countries as $code => $label ) : |
|
| 52 | - ?> |
|
| 51 | + foreach ( $countries as $code => $label ) : |
|
| 52 | + ?> |
|
| 53 | 53 | <option |
| 54 | 54 | value="<?php echo esc_attr( $code ); ?>" |
| 55 | 55 | <?php echo selected( $code, $language, false ); ?> |
@@ -57,48 +57,48 @@ discard block |
||
| 57 | 57 | <?php echo esc_html( $label ); ?> |
| 58 | 58 | </option> |
| 59 | 59 | <?php |
| 60 | - endforeach; |
|
| 61 | - } |
|
| 60 | + endforeach; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Returns select options html. |
|
| 65 | - * |
|
| 66 | - * @since 3.18.0 |
|
| 67 | - * |
|
| 68 | - * @return void Echoes select options or empty string if required params are not set. |
|
| 69 | - */ |
|
| 70 | - public function get_options_html() { |
|
| 71 | - $html = ''; |
|
| 63 | + /** |
|
| 64 | + * Returns select options html. |
|
| 65 | + * |
|
| 66 | + * @since 3.18.0 |
|
| 67 | + * |
|
| 68 | + * @return void Echoes select options or empty string if required params are not set. |
|
| 69 | + */ |
|
| 70 | + public function get_options_html() { |
|
| 71 | + $html = ''; |
|
| 72 | 72 | |
| 73 | - // Check whether the required params are set. |
|
| 74 | - if ( ! empty( $_POST['lang'] ) && ! empty( $_POST['value'] ) ) { // WPCS: CSRF, input var, sanitization ok. |
|
| 75 | - ob_start(); |
|
| 76 | - // Get the new options. |
|
| 77 | - $this->render_options( $_POST ); // WPCS: CSRF, input var, sanitization ok. |
|
| 73 | + // Check whether the required params are set. |
|
| 74 | + if ( ! empty( $_POST['lang'] ) && ! empty( $_POST['value'] ) ) { // WPCS: CSRF, input var, sanitization ok. |
|
| 75 | + ob_start(); |
|
| 76 | + // Get the new options. |
|
| 77 | + $this->render_options( $_POST ); // WPCS: CSRF, input var, sanitization ok. |
|
| 78 | 78 | |
| 79 | - $html = ob_get_clean(); |
|
| 80 | - } |
|
| 79 | + $html = ob_get_clean(); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - // Return the html. |
|
| 83 | - wp_send_json_success( $html ); |
|
| 84 | - } |
|
| 82 | + // Return the html. |
|
| 83 | + wp_send_json_success( $html ); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * Modify the field data attributes by adding`country-code` |
|
| 88 | - * to existing attributes. |
|
| 89 | - * |
|
| 90 | - * @param array $attributes Current data attributes. |
|
| 91 | - * |
|
| 92 | - * @since 3.18.0 |
|
| 93 | - * |
|
| 94 | - * @return array $attributes Modified attributes. |
|
| 95 | - */ |
|
| 96 | - public function add_country_codes_data( $attributes ) { |
|
| 97 | - // Add the country codes. |
|
| 98 | - $attributes['country-codes'] = json_encode( Wordlift_Countries::get_codes() ); |
|
| 86 | + /** |
|
| 87 | + * Modify the field data attributes by adding`country-code` |
|
| 88 | + * to existing attributes. |
|
| 89 | + * |
|
| 90 | + * @param array $attributes Current data attributes. |
|
| 91 | + * |
|
| 92 | + * @since 3.18.0 |
|
| 93 | + * |
|
| 94 | + * @return array $attributes Modified attributes. |
|
| 95 | + */ |
|
| 96 | + public function add_country_codes_data( $attributes ) { |
|
| 97 | + // Add the country codes. |
|
| 98 | + $attributes['country-codes'] = json_encode( Wordlift_Countries::get_codes() ); |
|
| 99 | 99 | |
| 100 | - // Return the attributes. |
|
| 101 | - return $attributes; |
|
| 102 | - } |
|
| 100 | + // Return the attributes. |
|
| 101 | + return $attributes; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | 104 | } |
@@ -27,34 +27,34 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | public function __construct() { |
| 29 | 29 | // Adds the country codes as data attribute to allow front-end validation. |
| 30 | - add_filter( 'wl_admin_select_element_data_attributes', array( $this, 'add_country_codes_data' ), 10, 1 ); |
|
| 30 | + add_filter('wl_admin_select_element_data_attributes', array($this, 'add_country_codes_data'), 10, 1); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * @inheritdoc |
| 35 | 35 | */ |
| 36 | - public function render_options( $params ) { |
|
| 36 | + public function render_options($params) { |
|
| 37 | 37 | // Print all the supported countries, preselecting the one configured |
| 38 | 38 | // in WP (or United Kingdom if not supported). We now use the `Wordlift_Countries` |
| 39 | 39 | // class which provides the list of countries supported by WordLift. |
| 40 | 40 | // |
| 41 | 41 | // https://github.com/insideout10/wordlift-plugin/issues/713 |
| 42 | 42 | |
| 43 | - $lang = ( isset( $params['lang'] ) ) ? $params['lang'] : false; |
|
| 43 | + $lang = (isset($params['lang'])) ? $params['lang'] : false; |
|
| 44 | 44 | |
| 45 | 45 | // Get WordLift's supported countries. |
| 46 | - $countries = Wordlift_Countries::get_countries( $lang ); |
|
| 46 | + $countries = Wordlift_Countries::get_countries($lang); |
|
| 47 | 47 | |
| 48 | 48 | // If we support WP's configured language, then use that, otherwise use English by default. |
| 49 | - $language = isset( $countries[ $params['value'] ] ) ? $params['value'] : 'uk'; |
|
| 49 | + $language = isset($countries[$params['value']]) ? $params['value'] : 'uk'; |
|
| 50 | 50 | |
| 51 | - foreach ( $countries as $code => $label ) : |
|
| 51 | + foreach ($countries as $code => $label) : |
|
| 52 | 52 | ?> |
| 53 | 53 | <option |
| 54 | - value="<?php echo esc_attr( $code ); ?>" |
|
| 55 | - <?php echo selected( $code, $language, false ); ?> |
|
| 54 | + value="<?php echo esc_attr($code); ?>" |
|
| 55 | + <?php echo selected($code, $language, false); ?> |
|
| 56 | 56 | > |
| 57 | - <?php echo esc_html( $label ); ?> |
|
| 57 | + <?php echo esc_html($label); ?> |
|
| 58 | 58 | </option> |
| 59 | 59 | <?php |
| 60 | 60 | endforeach; |
@@ -71,16 +71,16 @@ discard block |
||
| 71 | 71 | $html = ''; |
| 72 | 72 | |
| 73 | 73 | // Check whether the required params are set. |
| 74 | - if ( ! empty( $_POST['lang'] ) && ! empty( $_POST['value'] ) ) { // WPCS: CSRF, input var, sanitization ok. |
|
| 74 | + if ( ! empty($_POST['lang']) && ! empty($_POST['value'])) { // WPCS: CSRF, input var, sanitization ok. |
|
| 75 | 75 | ob_start(); |
| 76 | 76 | // Get the new options. |
| 77 | - $this->render_options( $_POST ); // WPCS: CSRF, input var, sanitization ok. |
|
| 77 | + $this->render_options($_POST); // WPCS: CSRF, input var, sanitization ok. |
|
| 78 | 78 | |
| 79 | 79 | $html = ob_get_clean(); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | // Return the html. |
| 83 | - wp_send_json_success( $html ); |
|
| 83 | + wp_send_json_success($html); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -93,9 +93,9 @@ discard block |
||
| 93 | 93 | * |
| 94 | 94 | * @return array $attributes Modified attributes. |
| 95 | 95 | */ |
| 96 | - public function add_country_codes_data( $attributes ) { |
|
| 96 | + public function add_country_codes_data($attributes) { |
|
| 97 | 97 | // Add the country codes. |
| 98 | - $attributes['country-codes'] = json_encode( Wordlift_Countries::get_codes() ); |
|
| 98 | + $attributes['country-codes'] = json_encode(Wordlift_Countries::get_codes()); |
|
| 99 | 99 | |
| 100 | 100 | // Return the attributes. |
| 101 | 101 | return $attributes; |
@@ -18,13 +18,13 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Admin_Select2_Element extends Wordlift_Admin_Select_Element { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @inheritdoc |
|
| 23 | - */ |
|
| 24 | - public function render_options( $params ) { |
|
| 25 | - // Loop through all params and add the options. |
|
| 26 | - foreach ( $params['options'] as $value => $label ) : |
|
| 27 | - ?> |
|
| 21 | + /** |
|
| 22 | + * @inheritdoc |
|
| 23 | + */ |
|
| 24 | + public function render_options( $params ) { |
|
| 25 | + // Loop through all params and add the options. |
|
| 26 | + foreach ( $params['options'] as $value => $label ) : |
|
| 27 | + ?> |
|
| 28 | 28 | <option |
| 29 | 29 | value="<?php echo esc_attr( $value ); ?>" |
| 30 | 30 | <?php selected( $params['value'], $value ); ?> |
@@ -32,20 +32,20 @@ discard block |
||
| 32 | 32 | <?php echo esc_html( $label ); ?> |
| 33 | 33 | </option> |
| 34 | 34 | <?php |
| 35 | - endforeach; |
|
| 36 | - } |
|
| 35 | + endforeach; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @inheritdoc |
|
| 40 | - */ |
|
| 41 | - protected function enqueue_resources() { |
|
| 42 | - // Enqueue select2 library js and css. |
|
| 43 | - // Underscore is needed for Select2's `templateResult` and `templateSelection` templates. |
|
| 44 | - wp_enqueue_script( 'wordlift-select2', plugin_dir_url( dirname( __FILE__ ) ) . 'js/select2/js/select2' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.js', array( |
|
| 45 | - 'jquery', |
|
| 46 | - 'underscore', |
|
| 47 | - ), '4.0.3' ); |
|
| 48 | - wp_enqueue_style( 'wordlift-select2', plugin_dir_url( dirname( __FILE__ ) ) . 'js/select2/css/select2' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', array(), '4.0.3' ); |
|
| 49 | - } |
|
| 38 | + /** |
|
| 39 | + * @inheritdoc |
|
| 40 | + */ |
|
| 41 | + protected function enqueue_resources() { |
|
| 42 | + // Enqueue select2 library js and css. |
|
| 43 | + // Underscore is needed for Select2's `templateResult` and `templateSelection` templates. |
|
| 44 | + wp_enqueue_script( 'wordlift-select2', plugin_dir_url( dirname( __FILE__ ) ) . 'js/select2/js/select2' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.js', array( |
|
| 45 | + 'jquery', |
|
| 46 | + 'underscore', |
|
| 47 | + ), '4.0.3' ); |
|
| 48 | + wp_enqueue_style( 'wordlift-select2', plugin_dir_url( dirname( __FILE__ ) ) . 'js/select2/css/select2' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', array(), '4.0.3' ); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | 51 | } |
@@ -21,15 +21,15 @@ discard block |
||
| 21 | 21 | /** |
| 22 | 22 | * @inheritdoc |
| 23 | 23 | */ |
| 24 | - public function render_options( $params ) { |
|
| 24 | + public function render_options($params) { |
|
| 25 | 25 | // Loop through all params and add the options. |
| 26 | - foreach ( $params['options'] as $value => $label ) : |
|
| 26 | + foreach ($params['options'] as $value => $label) : |
|
| 27 | 27 | ?> |
| 28 | 28 | <option |
| 29 | - value="<?php echo esc_attr( $value ); ?>" |
|
| 30 | - <?php selected( $params['value'], $value ); ?> |
|
| 29 | + value="<?php echo esc_attr($value); ?>" |
|
| 30 | + <?php selected($params['value'], $value); ?> |
|
| 31 | 31 | > |
| 32 | - <?php echo esc_html( $label ); ?> |
|
| 32 | + <?php echo esc_html($label); ?> |
|
| 33 | 33 | </option> |
| 34 | 34 | <?php |
| 35 | 35 | endforeach; |
@@ -41,11 +41,11 @@ discard block |
||
| 41 | 41 | protected function enqueue_resources() { |
| 42 | 42 | // Enqueue select2 library js and css. |
| 43 | 43 | // Underscore is needed for Select2's `templateResult` and `templateSelection` templates. |
| 44 | - wp_enqueue_script( 'wordlift-select2', plugin_dir_url( dirname( __FILE__ ) ) . 'js/select2/js/select2' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.js', array( |
|
| 44 | + wp_enqueue_script('wordlift-select2', plugin_dir_url(dirname(__FILE__)).'js/select2/js/select2'.( ! defined('SCRIPT_DEBUG') || ! SCRIPT_DEBUG ? '.min' : '').'.js', array( |
|
| 45 | 45 | 'jquery', |
| 46 | 46 | 'underscore', |
| 47 | - ), '4.0.3' ); |
|
| 48 | - wp_enqueue_style( 'wordlift-select2', plugin_dir_url( dirname( __FILE__ ) ) . 'js/select2/css/select2' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', array(), '4.0.3' ); |
|
| 47 | + ), '4.0.3'); |
|
| 48 | + wp_enqueue_style('wordlift-select2', plugin_dir_url(dirname(__FILE__)).'js/select2/css/select2'.( ! defined('SCRIPT_DEBUG') || ! SCRIPT_DEBUG ? '.min' : '').'.css', array(), '4.0.3'); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | } |
@@ -16,51 +16,51 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Wordlift_Install_Package_Type extends Wordlift_Install { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * The install version. |
|
| 21 | - * |
|
| 22 | - * @since 3.20.0 |
|
| 23 | - */ |
|
| 24 | - protected static $version = '3.20.0'; |
|
| 19 | + /** |
|
| 20 | + * The install version. |
|
| 21 | + * |
|
| 22 | + * @since 3.20.0 |
|
| 23 | + */ |
|
| 24 | + protected static $version = '3.20.0'; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Run the install procedure. |
|
| 28 | - * |
|
| 29 | - * @since 3.20.0 |
|
| 30 | - * |
|
| 31 | - * @return mixed The result. |
|
| 32 | - */ |
|
| 33 | - public function install() { |
|
| 26 | + /** |
|
| 27 | + * Run the install procedure. |
|
| 28 | + * |
|
| 29 | + * @since 3.20.0 |
|
| 30 | + * |
|
| 31 | + * @return mixed The result. |
|
| 32 | + */ |
|
| 33 | + public function install() { |
|
| 34 | 34 | |
| 35 | - $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
| 36 | - $key = $configuration_service->get_key(); |
|
| 35 | + $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
| 36 | + $key = $configuration_service->get_key(); |
|
| 37 | 37 | |
| 38 | - // Bail out if the `key` isn't set. |
|
| 39 | - if ( empty( $key ) ) { |
|
| 40 | - return; |
|
| 41 | - } |
|
| 38 | + // Bail out if the `key` isn't set. |
|
| 39 | + if ( empty( $key ) ) { |
|
| 40 | + return; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - // Calling this function will get and set the remote dataset and package type. |
|
| 44 | - $configuration_service->get_remote_dataset_uri( $key ); |
|
| 43 | + // Calling this function will get and set the remote dataset and package type. |
|
| 44 | + $configuration_service->get_remote_dataset_uri( $key ); |
|
| 45 | 45 | |
| 46 | - } |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Must install when the package type isn't set. |
|
| 50 | - * |
|
| 51 | - * https://github.com/insideout10/wordlift-plugin/issues/761 |
|
| 52 | - * |
|
| 53 | - * @since 3.20.0 |
|
| 54 | - * @return bool True if package type is set, otherwise false. |
|
| 55 | - */ |
|
| 56 | - public function must_install() { |
|
| 48 | + /** |
|
| 49 | + * Must install when the package type isn't set. |
|
| 50 | + * |
|
| 51 | + * https://github.com/insideout10/wordlift-plugin/issues/761 |
|
| 52 | + * |
|
| 53 | + * @since 3.20.0 |
|
| 54 | + * @return bool True if package type is set, otherwise false. |
|
| 55 | + */ |
|
| 56 | + public function must_install() { |
|
| 57 | 57 | |
| 58 | - $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
| 59 | - $key = $configuration_service->get_key(); |
|
| 60 | - $package_type = $configuration_service->get_package_type(); |
|
| 58 | + $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
| 59 | + $key = $configuration_service->get_key(); |
|
| 60 | + $package_type = $configuration_service->get_package_type(); |
|
| 61 | 61 | |
| 62 | - // We need to determine the package type if the `key` is set, but the `package_type` isn't. |
|
| 63 | - return is_admin() && ! empty( $key ) && empty( $package_type ); |
|
| 64 | - } |
|
| 62 | + // We need to determine the package type if the `key` is set, but the `package_type` isn't. |
|
| 63 | + return is_admin() && ! empty( $key ) && empty( $package_type ); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | 66 | } |
@@ -36,12 +36,12 @@ discard block |
||
| 36 | 36 | $key = $configuration_service->get_key(); |
| 37 | 37 | |
| 38 | 38 | // Bail out if the `key` isn't set. |
| 39 | - if ( empty( $key ) ) { |
|
| 39 | + if (empty($key)) { |
|
| 40 | 40 | return; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | // Calling this function will get and set the remote dataset and package type. |
| 44 | - $configuration_service->get_remote_dataset_uri( $key ); |
|
| 44 | + $configuration_service->get_remote_dataset_uri($key); |
|
| 45 | 45 | |
| 46 | 46 | } |
| 47 | 47 | |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | $package_type = $configuration_service->get_package_type(); |
| 61 | 61 | |
| 62 | 62 | // We need to determine the package type if the `key` is set, but the `package_type` isn't. |
| 63 | - return is_admin() && ! empty( $key ) && empty( $package_type ); |
|
| 63 | + return is_admin() && ! empty($key) && empty($package_type); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | } |