示例#1
0
 public function validate()
 {
     $validation = parent::validate();
     if ($validation) {
         if (!isset($this->args['required']) || !$this->args['required']) {
             if ($this->value == '') {
                 return true;
             }
         }
         $url_absolute_preg = "/https?:\\/\\/(www\\.)?([a-zA-Z0-9-_]+)\\.([a-zA-Z0-9]{2,4})([\\/\\s])?/i";
         if (!preg_match($url_absolute_preg, $this->value)) {
             /* on vérifie alors que c'est une URL locale
              * A optimiser !!!
              *  */
             $path_match = "/^\\/(([a-zA-Z0-9])+\\/?)+(([a-zA-Z0-9])+\\.?([a-zA-Z0-9]){0,3})?\$/i";
             //vérifie qu'une URL ressemble à /path/to/file.php
             if (!preg_match($path_match, $this->value)) {
                 $this->error_msg = $this->label . ' n\'est pas une URL valide.';
                 return false;
             } else {
                 return true;
             }
         } else {
             return true;
         }
     }
     return $validation;
 }
 public function __construct($name, $value = null, $id = null, $args = array(), $section = null)
 {
     parent::__construct($name, $value, $id, $args, $section);
     // Add the color picker css file
     \wp_enqueue_style('wp-color-picker');
     // Include our custom jQuery file with WordPress Color Picker dependency
     \wp_enqueue_script('zest-color-picker-admin', \plugin_dir_url(__FILE__) . 'js/color-script.js', array('jquery', 'wp-color-picker'), false, true);
 }
 public function test_save_input_value()
 {
     $name = 'nom';
     $value = 'test';
     $id = 'id_form_test';
     $post = new \stdClass();
     $post->ID = 42;
     $text = new Text($name, $value, $id);
     \WP_Mock::wpFunction('get_post', array('times' => 1, 'arg' => array($post->ID), 'return' => $post));
     \WP_Mock::wpFunction('update_post_meta', array('times' => 1, 'arg' => array($post->ID, $id, $value), 'return' => 4));
     $this->assertNotFalse($text->save($post->ID));
 }