Esempio n. 1
0
 /**
  * Normalizes an array with key-value pairs representing
  * a GP_Project object.
  *
  * @since 1.0.0
  *
  * @param array $args Arguments for a GP_Project object.
  * @return array Normalized arguments for a GP_Project object.
  */
 public function normalize_fields($args)
 {
     $args = (array) $args;
     if (isset($args['parent_project_id'])) {
         $args['parent_project_id'] = $this->force_false_to_null($args['parent_project_id']);
     }
     if (isset($args['slug']) && !$args['slug']) {
         $args['slug'] = $args['name'];
     }
     if (!empty($args['slug'])) {
         $args['slug'] = gp_sanitize_slug($args['slug']);
     }
     if (isset($args['path']) && !$args['path'] || !isset($args['path']) || is_null($args['path'])) {
         unset($args['path']);
     }
     if (isset($args['active'])) {
         if ('on' === $args['active']) {
             $args['active'] = 1;
         }
         if (!$args['active']) {
             $args['active'] = 0;
         }
     }
     return $args;
 }
Esempio n. 2
0
 function test_gp_sanitize_project_name()
 {
     $this->assertEquals(gp_sanitize_slug('plugin V1.2.1'), 'plugin-v1.2.1');
     $this->assertEquals(gp_sanitize_slug('plugin \\/<1.2.1>'), 'plugin');
     $this->assertEquals(gp_sanitize_slug('GlotPress&Plugin@1.1.1'), 'glotpressplugin1.1.1');
 }
Esempio n. 3
0
 /**
  * Normalizes an array with key-value pairs representing
  * a GP_Translation_Set object.
  *
  * @since 1.0.0
  *
  * @param array $args Arguments for a GP_Translation_Set object.
  * @return array Normalized arguments for a GP_Translation_Set object.
  */
 public function normalize_fields($args)
 {
     $args = (array) $args;
     if (isset($args['name']) && empty($args['name'])) {
         if (isset($args['locale']) && !empty($args['locale'])) {
             $locale = GP_locales::by_slug($args['locale']);
             $args['name'] = $locale->english_name;
         }
     }
     if (isset($args['slug']) && !$args['slug']) {
         $args['slug'] = 'default';
     }
     if (!empty($args['slug'])) {
         $args['slug'] = gp_sanitize_slug($args['slug']);
     }
     return $args;
 }