@@ -8,128 +8,128 @@ |
||
| 8 | 8 | class EE_Post_Content_Field extends EE_Text_Field_Base |
| 9 | 9 | { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * @param string $table_column |
|
| 13 | - * @param string $nicename |
|
| 14 | - * @param bool $nullable |
|
| 15 | - * @param null $default_value |
|
| 16 | - */ |
|
| 17 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 18 | - { |
|
| 19 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 20 | - $this->setSchemaType('object'); |
|
| 21 | - } |
|
| 11 | + /** |
|
| 12 | + * @param string $table_column |
|
| 13 | + * @param string $nicename |
|
| 14 | + * @param bool $nullable |
|
| 15 | + * @param null $default_value |
|
| 16 | + */ |
|
| 17 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 18 | + { |
|
| 19 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
| 20 | + $this->setSchemaType('object'); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * removes all tags which a WP Post wouldn't allow in its content normally |
|
| 26 | - * |
|
| 27 | - * @param string $value |
|
| 28 | - * @return string |
|
| 29 | - */ |
|
| 30 | - public function prepare_for_set($value) |
|
| 31 | - { |
|
| 32 | - if (! current_user_can('unfiltered_html')) { |
|
| 33 | - $value = wp_kses("$value", wp_kses_allowed_html('post')); |
|
| 34 | - } |
|
| 35 | - return parent::prepare_for_set($value); |
|
| 36 | - } |
|
| 24 | + /** |
|
| 25 | + * removes all tags which a WP Post wouldn't allow in its content normally |
|
| 26 | + * |
|
| 27 | + * @param string $value |
|
| 28 | + * @return string |
|
| 29 | + */ |
|
| 30 | + public function prepare_for_set($value) |
|
| 31 | + { |
|
| 32 | + if (! current_user_can('unfiltered_html')) { |
|
| 33 | + $value = wp_kses("$value", wp_kses_allowed_html('post')); |
|
| 34 | + } |
|
| 35 | + return parent::prepare_for_set($value); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Runs the content through `the_content`, or if prepares the content for placing in a form input |
|
| 42 | - * @param string $value_on_field_to_be_outputted |
|
| 43 | - * @param string $schema possible values: 'form_input' or null (if null, will run through 'the_content') |
|
| 44 | - * @return string |
|
| 45 | - * @throws EE_Error when WP_DEBUG is on and recursive calling is detected |
|
| 46 | - */ |
|
| 47 | - public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
| 48 | - { |
|
| 49 | - switch($schema){ |
|
| 50 | - case 'form_input': |
|
| 51 | - return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema); |
|
| 52 | - case 'the_content': |
|
| 40 | + /** |
|
| 41 | + * Runs the content through `the_content`, or if prepares the content for placing in a form input |
|
| 42 | + * @param string $value_on_field_to_be_outputted |
|
| 43 | + * @param string $schema possible values: 'form_input' or null (if null, will run through 'the_content') |
|
| 44 | + * @return string |
|
| 45 | + * @throws EE_Error when WP_DEBUG is on and recursive calling is detected |
|
| 46 | + */ |
|
| 47 | + public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
| 48 | + { |
|
| 49 | + switch($schema){ |
|
| 50 | + case 'form_input': |
|
| 51 | + return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema); |
|
| 52 | + case 'the_content': |
|
| 53 | 53 | |
| 54 | - if(doing_filter( 'the_content')){ |
|
| 55 | - if( defined('WP_DEBUG') && WP_DEBUG){ |
|
| 56 | - throw new EE_Error( |
|
| 57 | - sprintf( |
|
| 58 | - esc_html__('You have recursively called "%1$s" with %2$s set to %3$s which uses "%2$s" filter. You should use it with %2$s "%3$s" instead here.', 'event_espresso'), |
|
| 59 | - 'EE_Post_Content_Field::prepare_for_pretty_echoing', |
|
| 60 | - '$schema', |
|
| 61 | - 'the_content', |
|
| 62 | - 'the_content_wp_core_only' |
|
| 63 | - ) |
|
| 64 | - ); |
|
| 65 | - } else { |
|
| 66 | - return $this->prepare_for_pretty_echoing($value_on_field_to_be_outputted, 'the_content_wp_core_only'); |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - return apply_filters( |
|
| 70 | - 'the_content', |
|
| 71 | - parent::prepare_for_pretty_echoing( |
|
| 72 | - $value_on_field_to_be_outputted, |
|
| 73 | - $schema |
|
| 74 | - ) |
|
| 75 | - ); |
|
| 76 | - case 'the_content_wp_core_only': |
|
| 77 | - default: |
|
| 78 | - self::_setup_the_content_wp_core_only_filters(); |
|
| 79 | - $return_value = apply_filters( |
|
| 80 | - 'the_content_wp_core_only', |
|
| 81 | - parent::prepare_for_pretty_echoing( |
|
| 82 | - $value_on_field_to_be_outputted, |
|
| 83 | - $schema |
|
| 84 | - ) |
|
| 85 | - ); |
|
| 86 | - //ya know what? adding these filters is super fast. Let's just |
|
| 87 | - //avoid needing to maintain global state and set this up as-needed |
|
| 88 | - remove_all_filters('the_content_wp_core_only'); |
|
| 89 | - do_action( 'AHEE__EE_Post_Content_Field__prepare_for_pretty_echoing__the_content_wp_core_only__done'); |
|
| 90 | - return $return_value; |
|
| 91 | - } |
|
| 92 | - } |
|
| 54 | + if(doing_filter( 'the_content')){ |
|
| 55 | + if( defined('WP_DEBUG') && WP_DEBUG){ |
|
| 56 | + throw new EE_Error( |
|
| 57 | + sprintf( |
|
| 58 | + esc_html__('You have recursively called "%1$s" with %2$s set to %3$s which uses "%2$s" filter. You should use it with %2$s "%3$s" instead here.', 'event_espresso'), |
|
| 59 | + 'EE_Post_Content_Field::prepare_for_pretty_echoing', |
|
| 60 | + '$schema', |
|
| 61 | + 'the_content', |
|
| 62 | + 'the_content_wp_core_only' |
|
| 63 | + ) |
|
| 64 | + ); |
|
| 65 | + } else { |
|
| 66 | + return $this->prepare_for_pretty_echoing($value_on_field_to_be_outputted, 'the_content_wp_core_only'); |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + return apply_filters( |
|
| 70 | + 'the_content', |
|
| 71 | + parent::prepare_for_pretty_echoing( |
|
| 72 | + $value_on_field_to_be_outputted, |
|
| 73 | + $schema |
|
| 74 | + ) |
|
| 75 | + ); |
|
| 76 | + case 'the_content_wp_core_only': |
|
| 77 | + default: |
|
| 78 | + self::_setup_the_content_wp_core_only_filters(); |
|
| 79 | + $return_value = apply_filters( |
|
| 80 | + 'the_content_wp_core_only', |
|
| 81 | + parent::prepare_for_pretty_echoing( |
|
| 82 | + $value_on_field_to_be_outputted, |
|
| 83 | + $schema |
|
| 84 | + ) |
|
| 85 | + ); |
|
| 86 | + //ya know what? adding these filters is super fast. Let's just |
|
| 87 | + //avoid needing to maintain global state and set this up as-needed |
|
| 88 | + remove_all_filters('the_content_wp_core_only'); |
|
| 89 | + do_action( 'AHEE__EE_Post_Content_Field__prepare_for_pretty_echoing__the_content_wp_core_only__done'); |
|
| 90 | + return $return_value; |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | 94 | |
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Verifies we've setup the standard WP core filters on 'the_content_wp_core_only' filter |
|
| 98 | - */ |
|
| 99 | - protected static function _setup_the_content_wp_core_only_filters() |
|
| 100 | - { |
|
| 101 | - add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'run_shortcode'), 8); |
|
| 102 | - add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'autoembed'), 8); |
|
| 103 | - add_filter('the_content_wp_core_only', 'wptexturize', 10); |
|
| 104 | - add_filter('the_content_wp_core_only', 'wpautop', 10); |
|
| 105 | - add_filter('the_content_wp_core_only', 'shortcode_unautop', 10); |
|
| 106 | - add_filter('the_content_wp_core_only', 'prepend_attachment', 10); |
|
| 107 | - if(function_exists('wp_make_content_images_responsive')) { |
|
| 108 | - add_filter('the_content_wp_core_only', 'wp_make_content_images_responsive', 10); |
|
| 109 | - } |
|
| 110 | - add_filter('the_content_wp_core_only', 'do_shortcode', 11); |
|
| 111 | - add_filter('the_content_wp_core_only', 'convert_smilies', 20); |
|
| 112 | - } |
|
| 96 | + /** |
|
| 97 | + * Verifies we've setup the standard WP core filters on 'the_content_wp_core_only' filter |
|
| 98 | + */ |
|
| 99 | + protected static function _setup_the_content_wp_core_only_filters() |
|
| 100 | + { |
|
| 101 | + add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'run_shortcode'), 8); |
|
| 102 | + add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'autoembed'), 8); |
|
| 103 | + add_filter('the_content_wp_core_only', 'wptexturize', 10); |
|
| 104 | + add_filter('the_content_wp_core_only', 'wpautop', 10); |
|
| 105 | + add_filter('the_content_wp_core_only', 'shortcode_unautop', 10); |
|
| 106 | + add_filter('the_content_wp_core_only', 'prepend_attachment', 10); |
|
| 107 | + if(function_exists('wp_make_content_images_responsive')) { |
|
| 108 | + add_filter('the_content_wp_core_only', 'wp_make_content_images_responsive', 10); |
|
| 109 | + } |
|
| 110 | + add_filter('the_content_wp_core_only', 'do_shortcode', 11); |
|
| 111 | + add_filter('the_content_wp_core_only', 'convert_smilies', 20); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | 114 | |
| 115 | 115 | |
| 116 | - public function getSchemaProperties() |
|
| 117 | - { |
|
| 118 | - return array( |
|
| 119 | - 'raw' => array( |
|
| 120 | - 'description' => sprintf( |
|
| 121 | - __('%s - the content as it exists in the database.', 'event_espresso'), |
|
| 122 | - $this->get_nicename() |
|
| 123 | - ), |
|
| 124 | - 'type' => 'string' |
|
| 125 | - ), |
|
| 126 | - 'rendered' => array( |
|
| 127 | - 'description' => sprintf( |
|
| 128 | - __('%s - the content rendered for display.', 'event_espresso'), |
|
| 129 | - $this->get_nicename() |
|
| 130 | - ), |
|
| 131 | - 'type' => 'string' |
|
| 132 | - ) |
|
| 133 | - ); |
|
| 134 | - } |
|
| 116 | + public function getSchemaProperties() |
|
| 117 | + { |
|
| 118 | + return array( |
|
| 119 | + 'raw' => array( |
|
| 120 | + 'description' => sprintf( |
|
| 121 | + __('%s - the content as it exists in the database.', 'event_espresso'), |
|
| 122 | + $this->get_nicename() |
|
| 123 | + ), |
|
| 124 | + 'type' => 'string' |
|
| 125 | + ), |
|
| 126 | + 'rendered' => array( |
|
| 127 | + 'description' => sprintf( |
|
| 128 | + __('%s - the content rendered for display.', 'event_espresso'), |
|
| 129 | + $this->get_nicename() |
|
| 130 | + ), |
|
| 131 | + 'type' => 'string' |
|
| 132 | + ) |
|
| 133 | + ); |
|
| 134 | + } |
|
| 135 | 135 | } |
| 136 | 136 | \ No newline at end of file |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | public function prepare_for_set($value) |
| 31 | 31 | { |
| 32 | - if (! current_user_can('unfiltered_html')) { |
|
| 32 | + if ( ! current_user_can('unfiltered_html')) { |
|
| 33 | 33 | $value = wp_kses("$value", wp_kses_allowed_html('post')); |
| 34 | 34 | } |
| 35 | 35 | return parent::prepare_for_set($value); |
@@ -46,13 +46,13 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
| 48 | 48 | { |
| 49 | - switch($schema){ |
|
| 49 | + switch ($schema) { |
|
| 50 | 50 | case 'form_input': |
| 51 | 51 | return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema); |
| 52 | 52 | case 'the_content': |
| 53 | 53 | |
| 54 | - if(doing_filter( 'the_content')){ |
|
| 55 | - if( defined('WP_DEBUG') && WP_DEBUG){ |
|
| 54 | + if (doing_filter('the_content')) { |
|
| 55 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
| 56 | 56 | throw new EE_Error( |
| 57 | 57 | sprintf( |
| 58 | 58 | esc_html__('You have recursively called "%1$s" with %2$s set to %3$s which uses "%2$s" filter. You should use it with %2$s "%3$s" instead here.', 'event_espresso'), |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | //ya know what? adding these filters is super fast. Let's just |
| 87 | 87 | //avoid needing to maintain global state and set this up as-needed |
| 88 | 88 | remove_all_filters('the_content_wp_core_only'); |
| 89 | - do_action( 'AHEE__EE_Post_Content_Field__prepare_for_pretty_echoing__the_content_wp_core_only__done'); |
|
| 89 | + do_action('AHEE__EE_Post_Content_Field__prepare_for_pretty_echoing__the_content_wp_core_only__done'); |
|
| 90 | 90 | return $return_value; |
| 91 | 91 | } |
| 92 | 92 | } |
@@ -98,13 +98,13 @@ discard block |
||
| 98 | 98 | */ |
| 99 | 99 | protected static function _setup_the_content_wp_core_only_filters() |
| 100 | 100 | { |
| 101 | - add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'run_shortcode'), 8); |
|
| 102 | - add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'autoembed'), 8); |
|
| 101 | + add_filter('the_content_wp_core_only', array($GLOBALS['wp_embed'], 'run_shortcode'), 8); |
|
| 102 | + add_filter('the_content_wp_core_only', array($GLOBALS['wp_embed'], 'autoembed'), 8); |
|
| 103 | 103 | add_filter('the_content_wp_core_only', 'wptexturize', 10); |
| 104 | 104 | add_filter('the_content_wp_core_only', 'wpautop', 10); |
| 105 | 105 | add_filter('the_content_wp_core_only', 'shortcode_unautop', 10); |
| 106 | 106 | add_filter('the_content_wp_core_only', 'prepend_attachment', 10); |
| 107 | - if(function_exists('wp_make_content_images_responsive')) { |
|
| 107 | + if (function_exists('wp_make_content_images_responsive')) { |
|
| 108 | 108 | add_filter('the_content_wp_core_only', 'wp_make_content_images_responsive', 10); |
| 109 | 109 | } |
| 110 | 110 | add_filter('the_content_wp_core_only', 'do_shortcode', 11); |
@@ -21,643 +21,642 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | abstract class EE_Model_Field_Base implements HasSchemaInterface |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * The alias for the table the column belongs to. |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 28 | - protected $_table_alias; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * The actual db column name for the table |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - protected $_table_column; |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * The authoritative name for the table column (used by client code to reference the field). |
|
| 39 | - * @var string |
|
| 40 | - */ |
|
| 41 | - protected $_name; |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * A description for the field. |
|
| 46 | - * @var string |
|
| 47 | - */ |
|
| 48 | - protected $_nicename; |
|
| 49 | - |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Whether the field is nullable or not |
|
| 53 | - * @var bool |
|
| 54 | - */ |
|
| 55 | - protected $_nullable; |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * What the default value for the field should be. |
|
| 60 | - * @var mixed |
|
| 61 | - */ |
|
| 62 | - protected $_default_value; |
|
| 63 | - |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Other configuration for the field |
|
| 67 | - * @var mixed |
|
| 68 | - */ |
|
| 69 | - protected $_other_config; |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * The name of the model this field is instantiated for. |
|
| 74 | - * @var string |
|
| 75 | - */ |
|
| 76 | - protected $_model_name; |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * This should be a json-schema valid data type for the field. |
|
| 81 | - * @link http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2 |
|
| 82 | - * @var string |
|
| 83 | - */ |
|
| 84 | - private $_schema_type = 'string'; |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * If the schema has a defined format then it should be defined via this property. |
|
| 89 | - * @link http://json-schema.org/latest/json-schema-validation.html#rfc.section.7 |
|
| 90 | - * @var string |
|
| 91 | - */ |
|
| 92 | - private $_schema_format = ''; |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Indicates that the value of the field is managed exclusively by the server/model and not something |
|
| 97 | - * settable by client code. |
|
| 98 | - * @link http://json-schema.org/latest/json-schema-hypermedia.html#rfc.section.4.4 |
|
| 99 | - * @var bool |
|
| 100 | - */ |
|
| 101 | - private $_schema_readonly = false; |
|
| 102 | - |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @param string $table_column |
|
| 106 | - * @param string $nicename |
|
| 107 | - * @param bool $nullable |
|
| 108 | - * @param null $default_value |
|
| 109 | - */ |
|
| 110 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 111 | - { |
|
| 112 | - $this->_table_column = $table_column; |
|
| 113 | - $this->_nicename = $nicename; |
|
| 114 | - $this->_nullable = $nullable; |
|
| 115 | - $this->_default_value = $default_value; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @param $table_alias |
|
| 121 | - * @param $name |
|
| 122 | - * @param $model_name |
|
| 123 | - */ |
|
| 124 | - public function _construct_finalize($table_alias, $name, $model_name) |
|
| 125 | - { |
|
| 126 | - $this->_table_alias = $table_alias; |
|
| 127 | - $this->_name = $name; |
|
| 128 | - $this->_model_name = $model_name; |
|
| 129 | - /** |
|
| 130 | - * allow for changing the defaults |
|
| 131 | - */ |
|
| 132 | - $this->_nicename = apply_filters('FHEE__EE_Model_Field_Base___construct_finalize___nicename', |
|
| 133 | - $this->_nicename, $this); |
|
| 134 | - $this->_default_value = apply_filters('FHEE__EE_Model_Field_Base___construct_finalize___default_value', |
|
| 135 | - $this->_default_value, $this); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - public function get_table_alias() |
|
| 139 | - { |
|
| 140 | - return $this->_table_alias; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - public function get_table_column() |
|
| 144 | - { |
|
| 145 | - return $this->_table_column; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Returns the name of the model this field is on. Eg 'Event' or 'Ticket_Datetime' |
|
| 150 | - * |
|
| 151 | - * @return string |
|
| 152 | - */ |
|
| 153 | - public function get_model_name() |
|
| 154 | - { |
|
| 155 | - return $this->_model_name; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * @throws \EE_Error |
|
| 160 | - * @return string |
|
| 161 | - */ |
|
| 162 | - public function get_name() |
|
| 163 | - { |
|
| 164 | - if ($this->_name) { |
|
| 165 | - return $this->_name; |
|
| 166 | - } else { |
|
| 167 | - throw new EE_Error(sprintf(__("Model field '%s' has no name set. Did you make a model and forget to call the parent model constructor?", |
|
| 168 | - "event_espresso"), get_class($this))); |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - public function get_nicename() |
|
| 173 | - { |
|
| 174 | - return $this->_nicename; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - public function is_nullable() |
|
| 178 | - { |
|
| 179 | - return $this->_nullable; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * returns whether this field is an auto-increment field or not. If it is, then |
|
| 184 | - * on insertion it can be null. However, on updates it must be present. |
|
| 185 | - * |
|
| 186 | - * @return boolean |
|
| 187 | - */ |
|
| 188 | - public function is_auto_increment() |
|
| 189 | - { |
|
| 190 | - return false; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * The default value in the model object's value domain. See lengthy comment about |
|
| 195 | - * value domains at the top of EEM_Base |
|
| 196 | - * |
|
| 197 | - * @return mixed |
|
| 198 | - */ |
|
| 199 | - public function get_default_value() |
|
| 200 | - { |
|
| 201 | - return $this->_default_value; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Returns the table alias joined to the table column, however this isn't the right |
|
| 206 | - * table alias if the aliased table is being joined to. In that case, you can use |
|
| 207 | - * EE_Model_Parser::extract_table_alias_model_relation_chain_prefix() to find the table's current alias |
|
| 208 | - * in the current query |
|
| 209 | - * |
|
| 210 | - * @return string |
|
| 211 | - */ |
|
| 212 | - public function get_qualified_column() |
|
| 213 | - { |
|
| 214 | - return $this->get_table_alias() . "." . $this->get_table_column(); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * When get() is called on a model object (eg EE_Event), before returning its value, |
|
| 219 | - * call this function on it, allowing us to customize the returned value based on |
|
| 220 | - * the field's type. Eg, we may want to unserialize it, strip tags, etc. By default, |
|
| 221 | - * we simply return it. |
|
| 222 | - * |
|
| 223 | - * @param mixed $value_of_field_on_model_object |
|
| 224 | - * @return mixed |
|
| 225 | - */ |
|
| 226 | - public function prepare_for_get($value_of_field_on_model_object) |
|
| 227 | - { |
|
| 228 | - return $value_of_field_on_model_object; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * When inserting or updating a field on a model object, run this function on each |
|
| 233 | - * value to prepare it for insertion into the db. Generally this converts |
|
| 234 | - * the validated input on the model object into the format used in the DB. |
|
| 235 | - * |
|
| 236 | - * @param mixed $value_of_field_on_model_object |
|
| 237 | - * @return mixed |
|
| 238 | - */ |
|
| 239 | - public function prepare_for_use_in_db($value_of_field_on_model_object) |
|
| 240 | - { |
|
| 241 | - return $value_of_field_on_model_object; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * When creating a brand-new model object, or setting a particular value for one of its fields, this function |
|
| 246 | - * is called before setting it on the model object. We may want to strip slashes, unserialize the value, etc. |
|
| 247 | - * By default, we do nothing. |
|
| 248 | - * |
|
| 249 | - * If the model field is going to perform any validation on the input, this is where it should be done |
|
| 250 | - * (once the value is on the model object, it may be used in other ways besides putting it into the DB |
|
| 251 | - * so it's best to validate it right away). |
|
| 252 | - * |
|
| 253 | - * @param mixed $value_inputted_for_field_on_model_object |
|
| 254 | - * @return mixed |
|
| 255 | - */ |
|
| 256 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 257 | - { |
|
| 258 | - return $value_inputted_for_field_on_model_object; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * When instantiating a model object from DB results, this function is called before setting each field. |
|
| 264 | - * We may want to serialize the value, etc. By default, we return the value using prepare_for_set() method as that |
|
| 265 | - * is the one child classes will most often define. |
|
| 266 | - * |
|
| 267 | - * @param mixed $value_found_in_db_for_model_object |
|
| 268 | - * @return mixed |
|
| 269 | - */ |
|
| 270 | - public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
| 271 | - { |
|
| 272 | - return $this->prepare_for_set($value_found_in_db_for_model_object); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * When echoing a field's value on a model object, this function is run to prepare the value for presentation in a |
|
| 277 | - * webpage. For example, we may want to output floats with 2 decimal places by default, dates as "Monday Jan 12, |
|
| 278 | - * 2013, at 3:23pm" instead of |
|
| 279 | - * "8765678632", or any other modifications to how the value should be displayed, but not modified itself. |
|
| 280 | - * |
|
| 281 | - * @param mixed $value_on_field_to_be_outputted |
|
| 282 | - * @return mixed |
|
| 283 | - */ |
|
| 284 | - public function prepare_for_pretty_echoing($value_on_field_to_be_outputted) |
|
| 285 | - { |
|
| 286 | - return $value_on_field_to_be_outputted; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * Returns whatever is set as the nicename for the object. |
|
| 292 | - * @return string |
|
| 293 | - */ |
|
| 294 | - public function getSchemaDescription() |
|
| 295 | - { |
|
| 296 | - return $this->get_nicename(); |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * Returns whatever is set as the $_schema_type property for the object. |
|
| 302 | - * Note: this will automatically add 'null' to the schema if the object is_nullable() |
|
| 303 | - * @return string|array |
|
| 304 | - */ |
|
| 305 | - public function getSchemaType() |
|
| 306 | - { |
|
| 307 | - if ($this->is_nullable()) { |
|
| 308 | - $this->_schema_type = (array) $this->_schema_type; |
|
| 309 | - if (! in_array('null', $this->_schema_type)) { |
|
| 310 | - $this->_schema_type[] = 'null'; |
|
| 311 | - }; |
|
| 312 | - } |
|
| 313 | - return $this->_schema_type; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * Sets the _schema_type property. Child classes should call this in their constructors to override the default state |
|
| 319 | - * for this property. |
|
| 320 | - * @param string|array $type |
|
| 321 | - * @throws InvalidArgumentException |
|
| 322 | - */ |
|
| 323 | - protected function setSchemaType($type) |
|
| 324 | - { |
|
| 325 | - $this->validateSchemaType($type); |
|
| 326 | - $this->_schema_type = $type; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * This is usually present when the $_schema_type property is 'object'. Any child classes will need to override |
|
| 332 | - * this method and return the properties for the schema. |
|
| 333 | - * |
|
| 334 | - * The reason this is not a property on the class is because there may be filters set on the values for the property |
|
| 335 | - * that won't be exposed on construct. For example enum type schemas may have the enum values filtered. |
|
| 336 | - * |
|
| 337 | - * @return array |
|
| 338 | - */ |
|
| 339 | - public function getSchemaProperties() |
|
| 340 | - { |
|
| 341 | - return array(); |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * By default this returns the scalar default value that was sent in on the class prepped according to the class type |
|
| 348 | - * as the default. However, when there are schema properties, then the default property is setup to mirror the |
|
| 349 | - * property keys and correctly prepare the default according to that expected property value. |
|
| 350 | - * The getSchema method validates whether the schema for default is setup correctly or not according to the schema type |
|
| 351 | - * |
|
| 352 | - * @return mixed |
|
| 353 | - */ |
|
| 354 | - public function getSchemaDefault() |
|
| 355 | - { |
|
| 356 | - $default_value = $this->prepare_for_use_in_db($this->prepare_for_set($this->get_default_value())); |
|
| 357 | - $schema_properties = $this->getSchemaProperties(); |
|
| 358 | - |
|
| 359 | - //if this schema has properties than shape the default value to match the properties shape. |
|
| 360 | - if ($schema_properties) { |
|
| 361 | - $value_to_return = array(); |
|
| 362 | - foreach ($schema_properties as $property_key => $property_schema) { |
|
| 363 | - switch ($property_key) { |
|
| 364 | - case 'pretty': |
|
| 365 | - case 'rendered': |
|
| 366 | - $value_to_return[$property_key] = $this->prepare_for_pretty_echoing($this->prepare_for_set($default_value)); |
|
| 367 | - break; |
|
| 368 | - default: |
|
| 369 | - $value_to_return[$property_key] = $default_value; |
|
| 370 | - break; |
|
| 371 | - } |
|
| 372 | - } |
|
| 373 | - $default_value = $value_to_return; |
|
| 374 | - } |
|
| 375 | - return $default_value; |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - |
|
| 379 | - |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * If a child class has enum values, they should override this method and provide a simple array |
|
| 383 | - * of the enum values. |
|
| 384 | - |
|
| 385 | - * The reason this is not a property on the class is because there may be filterable enum values that |
|
| 386 | - * are set on the instantiated object that could be filtered after construct. |
|
| 387 | - * |
|
| 388 | - * @return array |
|
| 389 | - */ |
|
| 390 | - public function getSchemaEnum() |
|
| 391 | - { |
|
| 392 | - return array(); |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * This returns the value of the $_schema_format property on the object. |
|
| 398 | - * @return string |
|
| 399 | - */ |
|
| 400 | - public function getSchemaFormat() |
|
| 401 | - { |
|
| 402 | - return $this->_schema_format; |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * Sets the schema format property. |
|
| 408 | - * @throws InvalidArgumentException |
|
| 409 | - * @param string $format |
|
| 410 | - */ |
|
| 411 | - protected function setSchemaFormat($format) |
|
| 412 | - { |
|
| 413 | - $this->validateSchemaFormat($format); |
|
| 414 | - $this->_schema_format = $format; |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - |
|
| 418 | - /** |
|
| 419 | - * This returns the value of the $_schema_readonly property on the object. |
|
| 420 | - * @return bool |
|
| 421 | - */ |
|
| 422 | - public function getSchemaReadonly() |
|
| 423 | - { |
|
| 424 | - return $this->_schema_readonly; |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - |
|
| 428 | - /** |
|
| 429 | - * This sets the value for the $_schema_readonly property. |
|
| 430 | - * @param bool $readonly (only explicit boolean values are accepted) |
|
| 431 | - */ |
|
| 432 | - protected function setSchemaReadOnly($readonly) |
|
| 433 | - { |
|
| 434 | - if (! is_bool($readonly)) { |
|
| 435 | - throw new InvalidArgumentException( |
|
| 436 | - sprintf( |
|
| 437 | - esc_html__('The incoming argument (%s) must be a boolean.', 'event_espresso'), |
|
| 438 | - print_r($readonly, true) |
|
| 439 | - ) |
|
| 440 | - ); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - $this->_schema_readonly = $readonly; |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - |
|
| 447 | - |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * Return `%d`, `%s` or `%f` to indicate the data type for the field. |
|
| 451 | - * @uses _get_wpdb_data_type() |
|
| 452 | - * |
|
| 453 | - * @return string |
|
| 454 | - */ |
|
| 455 | - public function get_wpdb_data_type() |
|
| 456 | - { |
|
| 457 | - return $this->_get_wpdb_data_type(); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - |
|
| 461 | - /** |
|
| 462 | - * Return `%d`, `%s` or `%f` to indicate the data type for the field that should be indicated in wpdb queries. |
|
| 463 | - * @param string $type Included if a specific type is requested. |
|
| 464 | - * @uses get_schema_type() |
|
| 465 | - * @return string |
|
| 466 | - */ |
|
| 467 | - protected function _get_wpdb_data_type($type='') |
|
| 468 | - { |
|
| 469 | - $type = empty($type) ? $this->getSchemaType() : $type; |
|
| 470 | - |
|
| 471 | - //if type is an array, then different parsing is required. |
|
| 472 | - if (is_array($type)) { |
|
| 473 | - return $this->_get_wpdb_data_type_for_type_array($type); |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - $wpdb_type = '%s'; |
|
| 477 | - switch ($type) { |
|
| 478 | - case 'number': |
|
| 479 | - $wpdb_type = '%f'; |
|
| 480 | - break; |
|
| 481 | - case 'integer': |
|
| 482 | - case 'boolean': |
|
| 483 | - $wpdb_type = '%d'; |
|
| 484 | - break; |
|
| 485 | - case 'object': |
|
| 486 | - $properties = $this->getSchemaProperties(); |
|
| 487 | - if (isset($properties['raw'], $properties['raw']['type'])) { |
|
| 488 | - $wpdb_type = $this->_get_wpdb_data_type($properties['raw']['type']); |
|
| 489 | - } |
|
| 490 | - break; //leave at default |
|
| 491 | - } |
|
| 492 | - return $wpdb_type; |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - |
|
| 496 | - |
|
| 497 | - protected function _get_wpdb_data_type_for_type_array($type) |
|
| 498 | - { |
|
| 499 | - $type = (array) $type; |
|
| 500 | - //first let's flip because then we can do a faster key check |
|
| 501 | - $type = array_flip($type); |
|
| 502 | - |
|
| 503 | - //check for things that mean '%s' |
|
| 504 | - if (isset($type['string'],$type['object'],$type['array'])) { |
|
| 505 | - return '%s'; |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - //if makes it past the above condition and there's float in the array |
|
| 509 | - //then the type is %f |
|
| 510 | - if (isset($type['number'])) { |
|
| 511 | - return '%f'; |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - //if it makes it above the above conditions and there is an integer in the array |
|
| 515 | - //then the type is %d |
|
| 516 | - if (isset($type['integer'])) { |
|
| 517 | - return '%d'; |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - //anything else is a string |
|
| 521 | - return '%s'; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - |
|
| 525 | - /** |
|
| 526 | - * This returns elements used to represent this field in the json schema. |
|
| 527 | - * |
|
| 528 | - * @link http://json-schema.org/ |
|
| 529 | - * @return array |
|
| 530 | - */ |
|
| 531 | - public function getSchema() |
|
| 532 | - { |
|
| 533 | - $schema = array( |
|
| 534 | - 'description' => $this->getSchemaDescription(), |
|
| 535 | - 'type' => $this->getSchemaType(), |
|
| 536 | - 'readonly' => $this->getSchemaReadonly(), |
|
| 537 | - 'default' => $this->getSchemaDefault() |
|
| 538 | - ); |
|
| 539 | - |
|
| 540 | - //optional properties of the schema |
|
| 541 | - $enum = $this->getSchemaEnum(); |
|
| 542 | - $properties = $this->getSchemaProperties(); |
|
| 543 | - $format = $this->getSchemaFormat(); |
|
| 544 | - if ($enum) { |
|
| 545 | - $schema['enum'] = $enum; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - if ($properties) { |
|
| 549 | - $schema['properties'] = $properties; |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - if ($format) { |
|
| 553 | - $schema['format'] = $format; |
|
| 554 | - } |
|
| 555 | - return $schema; |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * Some fields are in the database-only, (ie, used in queries etc), but shouldn't necessarily be part |
|
| 560 | - * of the model objects (ie, client code shouldn't care to ever see their value... if client code does |
|
| 561 | - * want to see their value, then they shouldn't be db-only fields!) |
|
| 562 | - * Eg, when doing events as custom post types, querying the post_type is essential, but |
|
| 563 | - * post_type is irrelevant for EE_Event objects (because they will ALL be of post_type 'esp_event'). |
|
| 564 | - * By default, all fields aren't db-only. |
|
| 565 | - * |
|
| 566 | - * @return boolean |
|
| 567 | - */ |
|
| 568 | - public function is_db_only_field() |
|
| 569 | - { |
|
| 570 | - return false; |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - |
|
| 574 | - /** |
|
| 575 | - * Validates the incoming string|array to ensure its an allowable type. |
|
| 576 | - * @throws InvalidArgumentException |
|
| 577 | - * @param string|array $type |
|
| 578 | - */ |
|
| 579 | - private function validateSchemaType($type) |
|
| 580 | - { |
|
| 581 | - if (! (is_string($type) || is_array($type))) { |
|
| 582 | - throw new InvalidArgumentException( |
|
| 583 | - sprintf( |
|
| 584 | - esc_html__('The incoming argument (%s) must be a string or an array.', 'event_espresso'), |
|
| 585 | - print_r($type, true) |
|
| 586 | - ) |
|
| 587 | - ); |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - //validate allowable types. |
|
| 591 | - //@link http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2 |
|
| 592 | - $allowable_types = array_flip( |
|
| 593 | - array( |
|
| 594 | - 'string', |
|
| 595 | - 'number', |
|
| 596 | - 'null', |
|
| 597 | - 'object', |
|
| 598 | - 'array', |
|
| 599 | - 'boolean', |
|
| 600 | - 'integer' |
|
| 601 | - ) |
|
| 602 | - ); |
|
| 603 | - |
|
| 604 | - if (is_array($type)) { |
|
| 605 | - foreach ($type as $item_in_type) { |
|
| 606 | - $this->validateSchemaType($item_in_type); |
|
| 607 | - } |
|
| 608 | - return; |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - if (! isset($allowable_types[$type])) { |
|
| 612 | - throw new InvalidArgumentException( |
|
| 613 | - sprintf( |
|
| 614 | - esc_html__('The incoming argument (%1$s) must be one of the allowable types: %2$s', 'event_espresso'), |
|
| 615 | - $type, |
|
| 616 | - implode(',', array_flip($allowable_types)) |
|
| 617 | - ) |
|
| 618 | - ); |
|
| 619 | - } |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - |
|
| 623 | - /** |
|
| 624 | - * Validates that the incoming format is an allowable string to use for the _schema_format property |
|
| 625 | - * @throws InvalidArgumentException |
|
| 626 | - * @param $format |
|
| 627 | - */ |
|
| 628 | - private function validateSchemaFormat($format) |
|
| 629 | - { |
|
| 630 | - if (! is_string($format)) { |
|
| 631 | - throw new InvalidArgumentException( |
|
| 632 | - sprintf( |
|
| 633 | - esc_html__('The incoming argument (%s) must be a string.', 'event_espresso'), |
|
| 634 | - print_r($format, true) |
|
| 635 | - ) |
|
| 636 | - ); |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - //validate allowable format values |
|
| 640 | - //@link http://json-schema.org/latest/json-schema-validation.html#rfc.section.7 |
|
| 641 | - $allowable_formats = array_flip( |
|
| 642 | - array( |
|
| 643 | - 'date-time', |
|
| 644 | - 'email', |
|
| 645 | - 'hostname', |
|
| 646 | - 'ipv4', |
|
| 647 | - 'ipv6', |
|
| 648 | - 'uri', |
|
| 649 | - 'uriref' |
|
| 650 | - ) |
|
| 651 | - ); |
|
| 652 | - |
|
| 653 | - if (! isset($allowable_formats[$format])) { |
|
| 654 | - throw new InvalidArgumentException( |
|
| 655 | - sprintf( |
|
| 656 | - esc_html__('The incoming argument (%1$s) must be one of the allowable formats: %2$s', 'event_espresso'), |
|
| 657 | - $format, |
|
| 658 | - implode(',', array_flip($allowable_formats)) |
|
| 659 | - ) |
|
| 660 | - ); |
|
| 661 | - } |
|
| 662 | - } |
|
| 24 | + /** |
|
| 25 | + * The alias for the table the column belongs to. |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | + protected $_table_alias; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * The actual db column name for the table |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + protected $_table_column; |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * The authoritative name for the table column (used by client code to reference the field). |
|
| 39 | + * @var string |
|
| 40 | + */ |
|
| 41 | + protected $_name; |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * A description for the field. |
|
| 46 | + * @var string |
|
| 47 | + */ |
|
| 48 | + protected $_nicename; |
|
| 49 | + |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Whether the field is nullable or not |
|
| 53 | + * @var bool |
|
| 54 | + */ |
|
| 55 | + protected $_nullable; |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * What the default value for the field should be. |
|
| 60 | + * @var mixed |
|
| 61 | + */ |
|
| 62 | + protected $_default_value; |
|
| 63 | + |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Other configuration for the field |
|
| 67 | + * @var mixed |
|
| 68 | + */ |
|
| 69 | + protected $_other_config; |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * The name of the model this field is instantiated for. |
|
| 74 | + * @var string |
|
| 75 | + */ |
|
| 76 | + protected $_model_name; |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * This should be a json-schema valid data type for the field. |
|
| 81 | + * @link http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2 |
|
| 82 | + * @var string |
|
| 83 | + */ |
|
| 84 | + private $_schema_type = 'string'; |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * If the schema has a defined format then it should be defined via this property. |
|
| 89 | + * @link http://json-schema.org/latest/json-schema-validation.html#rfc.section.7 |
|
| 90 | + * @var string |
|
| 91 | + */ |
|
| 92 | + private $_schema_format = ''; |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Indicates that the value of the field is managed exclusively by the server/model and not something |
|
| 97 | + * settable by client code. |
|
| 98 | + * @link http://json-schema.org/latest/json-schema-hypermedia.html#rfc.section.4.4 |
|
| 99 | + * @var bool |
|
| 100 | + */ |
|
| 101 | + private $_schema_readonly = false; |
|
| 102 | + |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @param string $table_column |
|
| 106 | + * @param string $nicename |
|
| 107 | + * @param bool $nullable |
|
| 108 | + * @param null $default_value |
|
| 109 | + */ |
|
| 110 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
| 111 | + { |
|
| 112 | + $this->_table_column = $table_column; |
|
| 113 | + $this->_nicename = $nicename; |
|
| 114 | + $this->_nullable = $nullable; |
|
| 115 | + $this->_default_value = $default_value; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @param $table_alias |
|
| 121 | + * @param $name |
|
| 122 | + * @param $model_name |
|
| 123 | + */ |
|
| 124 | + public function _construct_finalize($table_alias, $name, $model_name) |
|
| 125 | + { |
|
| 126 | + $this->_table_alias = $table_alias; |
|
| 127 | + $this->_name = $name; |
|
| 128 | + $this->_model_name = $model_name; |
|
| 129 | + /** |
|
| 130 | + * allow for changing the defaults |
|
| 131 | + */ |
|
| 132 | + $this->_nicename = apply_filters('FHEE__EE_Model_Field_Base___construct_finalize___nicename', |
|
| 133 | + $this->_nicename, $this); |
|
| 134 | + $this->_default_value = apply_filters('FHEE__EE_Model_Field_Base___construct_finalize___default_value', |
|
| 135 | + $this->_default_value, $this); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + public function get_table_alias() |
|
| 139 | + { |
|
| 140 | + return $this->_table_alias; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + public function get_table_column() |
|
| 144 | + { |
|
| 145 | + return $this->_table_column; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Returns the name of the model this field is on. Eg 'Event' or 'Ticket_Datetime' |
|
| 150 | + * |
|
| 151 | + * @return string |
|
| 152 | + */ |
|
| 153 | + public function get_model_name() |
|
| 154 | + { |
|
| 155 | + return $this->_model_name; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * @throws \EE_Error |
|
| 160 | + * @return string |
|
| 161 | + */ |
|
| 162 | + public function get_name() |
|
| 163 | + { |
|
| 164 | + if ($this->_name) { |
|
| 165 | + return $this->_name; |
|
| 166 | + } else { |
|
| 167 | + throw new EE_Error(sprintf(__("Model field '%s' has no name set. Did you make a model and forget to call the parent model constructor?", |
|
| 168 | + "event_espresso"), get_class($this))); |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + public function get_nicename() |
|
| 173 | + { |
|
| 174 | + return $this->_nicename; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + public function is_nullable() |
|
| 178 | + { |
|
| 179 | + return $this->_nullable; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * returns whether this field is an auto-increment field or not. If it is, then |
|
| 184 | + * on insertion it can be null. However, on updates it must be present. |
|
| 185 | + * |
|
| 186 | + * @return boolean |
|
| 187 | + */ |
|
| 188 | + public function is_auto_increment() |
|
| 189 | + { |
|
| 190 | + return false; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * The default value in the model object's value domain. See lengthy comment about |
|
| 195 | + * value domains at the top of EEM_Base |
|
| 196 | + * |
|
| 197 | + * @return mixed |
|
| 198 | + */ |
|
| 199 | + public function get_default_value() |
|
| 200 | + { |
|
| 201 | + return $this->_default_value; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Returns the table alias joined to the table column, however this isn't the right |
|
| 206 | + * table alias if the aliased table is being joined to. In that case, you can use |
|
| 207 | + * EE_Model_Parser::extract_table_alias_model_relation_chain_prefix() to find the table's current alias |
|
| 208 | + * in the current query |
|
| 209 | + * |
|
| 210 | + * @return string |
|
| 211 | + */ |
|
| 212 | + public function get_qualified_column() |
|
| 213 | + { |
|
| 214 | + return $this->get_table_alias() . "." . $this->get_table_column(); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * When get() is called on a model object (eg EE_Event), before returning its value, |
|
| 219 | + * call this function on it, allowing us to customize the returned value based on |
|
| 220 | + * the field's type. Eg, we may want to unserialize it, strip tags, etc. By default, |
|
| 221 | + * we simply return it. |
|
| 222 | + * |
|
| 223 | + * @param mixed $value_of_field_on_model_object |
|
| 224 | + * @return mixed |
|
| 225 | + */ |
|
| 226 | + public function prepare_for_get($value_of_field_on_model_object) |
|
| 227 | + { |
|
| 228 | + return $value_of_field_on_model_object; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * When inserting or updating a field on a model object, run this function on each |
|
| 233 | + * value to prepare it for insertion into the db. Generally this converts |
|
| 234 | + * the validated input on the model object into the format used in the DB. |
|
| 235 | + * |
|
| 236 | + * @param mixed $value_of_field_on_model_object |
|
| 237 | + * @return mixed |
|
| 238 | + */ |
|
| 239 | + public function prepare_for_use_in_db($value_of_field_on_model_object) |
|
| 240 | + { |
|
| 241 | + return $value_of_field_on_model_object; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * When creating a brand-new model object, or setting a particular value for one of its fields, this function |
|
| 246 | + * is called before setting it on the model object. We may want to strip slashes, unserialize the value, etc. |
|
| 247 | + * By default, we do nothing. |
|
| 248 | + * |
|
| 249 | + * If the model field is going to perform any validation on the input, this is where it should be done |
|
| 250 | + * (once the value is on the model object, it may be used in other ways besides putting it into the DB |
|
| 251 | + * so it's best to validate it right away). |
|
| 252 | + * |
|
| 253 | + * @param mixed $value_inputted_for_field_on_model_object |
|
| 254 | + * @return mixed |
|
| 255 | + */ |
|
| 256 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 257 | + { |
|
| 258 | + return $value_inputted_for_field_on_model_object; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * When instantiating a model object from DB results, this function is called before setting each field. |
|
| 264 | + * We may want to serialize the value, etc. By default, we return the value using prepare_for_set() method as that |
|
| 265 | + * is the one child classes will most often define. |
|
| 266 | + * |
|
| 267 | + * @param mixed $value_found_in_db_for_model_object |
|
| 268 | + * @return mixed |
|
| 269 | + */ |
|
| 270 | + public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
| 271 | + { |
|
| 272 | + return $this->prepare_for_set($value_found_in_db_for_model_object); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * When echoing a field's value on a model object, this function is run to prepare the value for presentation in a |
|
| 277 | + * webpage. For example, we may want to output floats with 2 decimal places by default, dates as "Monday Jan 12, |
|
| 278 | + * 2013, at 3:23pm" instead of |
|
| 279 | + * "8765678632", or any other modifications to how the value should be displayed, but not modified itself. |
|
| 280 | + * |
|
| 281 | + * @param mixed $value_on_field_to_be_outputted |
|
| 282 | + * @return mixed |
|
| 283 | + */ |
|
| 284 | + public function prepare_for_pretty_echoing($value_on_field_to_be_outputted) |
|
| 285 | + { |
|
| 286 | + return $value_on_field_to_be_outputted; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * Returns whatever is set as the nicename for the object. |
|
| 292 | + * @return string |
|
| 293 | + */ |
|
| 294 | + public function getSchemaDescription() |
|
| 295 | + { |
|
| 296 | + return $this->get_nicename(); |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * Returns whatever is set as the $_schema_type property for the object. |
|
| 302 | + * Note: this will automatically add 'null' to the schema if the object is_nullable() |
|
| 303 | + * @return string|array |
|
| 304 | + */ |
|
| 305 | + public function getSchemaType() |
|
| 306 | + { |
|
| 307 | + if ($this->is_nullable()) { |
|
| 308 | + $this->_schema_type = (array) $this->_schema_type; |
|
| 309 | + if (! in_array('null', $this->_schema_type)) { |
|
| 310 | + $this->_schema_type[] = 'null'; |
|
| 311 | + }; |
|
| 312 | + } |
|
| 313 | + return $this->_schema_type; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * Sets the _schema_type property. Child classes should call this in their constructors to override the default state |
|
| 319 | + * for this property. |
|
| 320 | + * @param string|array $type |
|
| 321 | + * @throws InvalidArgumentException |
|
| 322 | + */ |
|
| 323 | + protected function setSchemaType($type) |
|
| 324 | + { |
|
| 325 | + $this->validateSchemaType($type); |
|
| 326 | + $this->_schema_type = $type; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * This is usually present when the $_schema_type property is 'object'. Any child classes will need to override |
|
| 332 | + * this method and return the properties for the schema. |
|
| 333 | + * |
|
| 334 | + * The reason this is not a property on the class is because there may be filters set on the values for the property |
|
| 335 | + * that won't be exposed on construct. For example enum type schemas may have the enum values filtered. |
|
| 336 | + * |
|
| 337 | + * @return array |
|
| 338 | + */ |
|
| 339 | + public function getSchemaProperties() |
|
| 340 | + { |
|
| 341 | + return array(); |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * By default this returns the scalar default value that was sent in on the class prepped according to the class type |
|
| 348 | + * as the default. However, when there are schema properties, then the default property is setup to mirror the |
|
| 349 | + * property keys and correctly prepare the default according to that expected property value. |
|
| 350 | + * The getSchema method validates whether the schema for default is setup correctly or not according to the schema type |
|
| 351 | + * |
|
| 352 | + * @return mixed |
|
| 353 | + */ |
|
| 354 | + public function getSchemaDefault() |
|
| 355 | + { |
|
| 356 | + $default_value = $this->prepare_for_use_in_db($this->prepare_for_set($this->get_default_value())); |
|
| 357 | + $schema_properties = $this->getSchemaProperties(); |
|
| 358 | + |
|
| 359 | + //if this schema has properties than shape the default value to match the properties shape. |
|
| 360 | + if ($schema_properties) { |
|
| 361 | + $value_to_return = array(); |
|
| 362 | + foreach ($schema_properties as $property_key => $property_schema) { |
|
| 363 | + switch ($property_key) { |
|
| 364 | + case 'pretty': |
|
| 365 | + case 'rendered': |
|
| 366 | + $value_to_return[$property_key] = $this->prepare_for_pretty_echoing($this->prepare_for_set($default_value)); |
|
| 367 | + break; |
|
| 368 | + default: |
|
| 369 | + $value_to_return[$property_key] = $default_value; |
|
| 370 | + break; |
|
| 371 | + } |
|
| 372 | + } |
|
| 373 | + $default_value = $value_to_return; |
|
| 374 | + } |
|
| 375 | + return $default_value; |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + |
|
| 379 | + |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * If a child class has enum values, they should override this method and provide a simple array |
|
| 383 | + * of the enum values. |
|
| 384 | + * The reason this is not a property on the class is because there may be filterable enum values that |
|
| 385 | + * are set on the instantiated object that could be filtered after construct. |
|
| 386 | + * |
|
| 387 | + * @return array |
|
| 388 | + */ |
|
| 389 | + public function getSchemaEnum() |
|
| 390 | + { |
|
| 391 | + return array(); |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * This returns the value of the $_schema_format property on the object. |
|
| 397 | + * @return string |
|
| 398 | + */ |
|
| 399 | + public function getSchemaFormat() |
|
| 400 | + { |
|
| 401 | + return $this->_schema_format; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * Sets the schema format property. |
|
| 407 | + * @throws InvalidArgumentException |
|
| 408 | + * @param string $format |
|
| 409 | + */ |
|
| 410 | + protected function setSchemaFormat($format) |
|
| 411 | + { |
|
| 412 | + $this->validateSchemaFormat($format); |
|
| 413 | + $this->_schema_format = $format; |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * This returns the value of the $_schema_readonly property on the object. |
|
| 419 | + * @return bool |
|
| 420 | + */ |
|
| 421 | + public function getSchemaReadonly() |
|
| 422 | + { |
|
| 423 | + return $this->_schema_readonly; |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + |
|
| 427 | + /** |
|
| 428 | + * This sets the value for the $_schema_readonly property. |
|
| 429 | + * @param bool $readonly (only explicit boolean values are accepted) |
|
| 430 | + */ |
|
| 431 | + protected function setSchemaReadOnly($readonly) |
|
| 432 | + { |
|
| 433 | + if (! is_bool($readonly)) { |
|
| 434 | + throw new InvalidArgumentException( |
|
| 435 | + sprintf( |
|
| 436 | + esc_html__('The incoming argument (%s) must be a boolean.', 'event_espresso'), |
|
| 437 | + print_r($readonly, true) |
|
| 438 | + ) |
|
| 439 | + ); |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + $this->_schema_readonly = $readonly; |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + |
|
| 446 | + |
|
| 447 | + |
|
| 448 | + /** |
|
| 449 | + * Return `%d`, `%s` or `%f` to indicate the data type for the field. |
|
| 450 | + * @uses _get_wpdb_data_type() |
|
| 451 | + * |
|
| 452 | + * @return string |
|
| 453 | + */ |
|
| 454 | + public function get_wpdb_data_type() |
|
| 455 | + { |
|
| 456 | + return $this->_get_wpdb_data_type(); |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * Return `%d`, `%s` or `%f` to indicate the data type for the field that should be indicated in wpdb queries. |
|
| 462 | + * @param string $type Included if a specific type is requested. |
|
| 463 | + * @uses get_schema_type() |
|
| 464 | + * @return string |
|
| 465 | + */ |
|
| 466 | + protected function _get_wpdb_data_type($type='') |
|
| 467 | + { |
|
| 468 | + $type = empty($type) ? $this->getSchemaType() : $type; |
|
| 469 | + |
|
| 470 | + //if type is an array, then different parsing is required. |
|
| 471 | + if (is_array($type)) { |
|
| 472 | + return $this->_get_wpdb_data_type_for_type_array($type); |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + $wpdb_type = '%s'; |
|
| 476 | + switch ($type) { |
|
| 477 | + case 'number': |
|
| 478 | + $wpdb_type = '%f'; |
|
| 479 | + break; |
|
| 480 | + case 'integer': |
|
| 481 | + case 'boolean': |
|
| 482 | + $wpdb_type = '%d'; |
|
| 483 | + break; |
|
| 484 | + case 'object': |
|
| 485 | + $properties = $this->getSchemaProperties(); |
|
| 486 | + if (isset($properties['raw'], $properties['raw']['type'])) { |
|
| 487 | + $wpdb_type = $this->_get_wpdb_data_type($properties['raw']['type']); |
|
| 488 | + } |
|
| 489 | + break; //leave at default |
|
| 490 | + } |
|
| 491 | + return $wpdb_type; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + |
|
| 495 | + |
|
| 496 | + protected function _get_wpdb_data_type_for_type_array($type) |
|
| 497 | + { |
|
| 498 | + $type = (array) $type; |
|
| 499 | + //first let's flip because then we can do a faster key check |
|
| 500 | + $type = array_flip($type); |
|
| 501 | + |
|
| 502 | + //check for things that mean '%s' |
|
| 503 | + if (isset($type['string'],$type['object'],$type['array'])) { |
|
| 504 | + return '%s'; |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + //if makes it past the above condition and there's float in the array |
|
| 508 | + //then the type is %f |
|
| 509 | + if (isset($type['number'])) { |
|
| 510 | + return '%f'; |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + //if it makes it above the above conditions and there is an integer in the array |
|
| 514 | + //then the type is %d |
|
| 515 | + if (isset($type['integer'])) { |
|
| 516 | + return '%d'; |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + //anything else is a string |
|
| 520 | + return '%s'; |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + |
|
| 524 | + /** |
|
| 525 | + * This returns elements used to represent this field in the json schema. |
|
| 526 | + * |
|
| 527 | + * @link http://json-schema.org/ |
|
| 528 | + * @return array |
|
| 529 | + */ |
|
| 530 | + public function getSchema() |
|
| 531 | + { |
|
| 532 | + $schema = array( |
|
| 533 | + 'description' => $this->getSchemaDescription(), |
|
| 534 | + 'type' => $this->getSchemaType(), |
|
| 535 | + 'readonly' => $this->getSchemaReadonly(), |
|
| 536 | + 'default' => $this->getSchemaDefault() |
|
| 537 | + ); |
|
| 538 | + |
|
| 539 | + //optional properties of the schema |
|
| 540 | + $enum = $this->getSchemaEnum(); |
|
| 541 | + $properties = $this->getSchemaProperties(); |
|
| 542 | + $format = $this->getSchemaFormat(); |
|
| 543 | + if ($enum) { |
|
| 544 | + $schema['enum'] = $enum; |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + if ($properties) { |
|
| 548 | + $schema['properties'] = $properties; |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + if ($format) { |
|
| 552 | + $schema['format'] = $format; |
|
| 553 | + } |
|
| 554 | + return $schema; |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + /** |
|
| 558 | + * Some fields are in the database-only, (ie, used in queries etc), but shouldn't necessarily be part |
|
| 559 | + * of the model objects (ie, client code shouldn't care to ever see their value... if client code does |
|
| 560 | + * want to see their value, then they shouldn't be db-only fields!) |
|
| 561 | + * Eg, when doing events as custom post types, querying the post_type is essential, but |
|
| 562 | + * post_type is irrelevant for EE_Event objects (because they will ALL be of post_type 'esp_event'). |
|
| 563 | + * By default, all fields aren't db-only. |
|
| 564 | + * |
|
| 565 | + * @return boolean |
|
| 566 | + */ |
|
| 567 | + public function is_db_only_field() |
|
| 568 | + { |
|
| 569 | + return false; |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + |
|
| 573 | + /** |
|
| 574 | + * Validates the incoming string|array to ensure its an allowable type. |
|
| 575 | + * @throws InvalidArgumentException |
|
| 576 | + * @param string|array $type |
|
| 577 | + */ |
|
| 578 | + private function validateSchemaType($type) |
|
| 579 | + { |
|
| 580 | + if (! (is_string($type) || is_array($type))) { |
|
| 581 | + throw new InvalidArgumentException( |
|
| 582 | + sprintf( |
|
| 583 | + esc_html__('The incoming argument (%s) must be a string or an array.', 'event_espresso'), |
|
| 584 | + print_r($type, true) |
|
| 585 | + ) |
|
| 586 | + ); |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + //validate allowable types. |
|
| 590 | + //@link http://json-schema.org/latest/json-schema-core.html#rfc.section.4.2 |
|
| 591 | + $allowable_types = array_flip( |
|
| 592 | + array( |
|
| 593 | + 'string', |
|
| 594 | + 'number', |
|
| 595 | + 'null', |
|
| 596 | + 'object', |
|
| 597 | + 'array', |
|
| 598 | + 'boolean', |
|
| 599 | + 'integer' |
|
| 600 | + ) |
|
| 601 | + ); |
|
| 602 | + |
|
| 603 | + if (is_array($type)) { |
|
| 604 | + foreach ($type as $item_in_type) { |
|
| 605 | + $this->validateSchemaType($item_in_type); |
|
| 606 | + } |
|
| 607 | + return; |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + if (! isset($allowable_types[$type])) { |
|
| 611 | + throw new InvalidArgumentException( |
|
| 612 | + sprintf( |
|
| 613 | + esc_html__('The incoming argument (%1$s) must be one of the allowable types: %2$s', 'event_espresso'), |
|
| 614 | + $type, |
|
| 615 | + implode(',', array_flip($allowable_types)) |
|
| 616 | + ) |
|
| 617 | + ); |
|
| 618 | + } |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + |
|
| 622 | + /** |
|
| 623 | + * Validates that the incoming format is an allowable string to use for the _schema_format property |
|
| 624 | + * @throws InvalidArgumentException |
|
| 625 | + * @param $format |
|
| 626 | + */ |
|
| 627 | + private function validateSchemaFormat($format) |
|
| 628 | + { |
|
| 629 | + if (! is_string($format)) { |
|
| 630 | + throw new InvalidArgumentException( |
|
| 631 | + sprintf( |
|
| 632 | + esc_html__('The incoming argument (%s) must be a string.', 'event_espresso'), |
|
| 633 | + print_r($format, true) |
|
| 634 | + ) |
|
| 635 | + ); |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + //validate allowable format values |
|
| 639 | + //@link http://json-schema.org/latest/json-schema-validation.html#rfc.section.7 |
|
| 640 | + $allowable_formats = array_flip( |
|
| 641 | + array( |
|
| 642 | + 'date-time', |
|
| 643 | + 'email', |
|
| 644 | + 'hostname', |
|
| 645 | + 'ipv4', |
|
| 646 | + 'ipv6', |
|
| 647 | + 'uri', |
|
| 648 | + 'uriref' |
|
| 649 | + ) |
|
| 650 | + ); |
|
| 651 | + |
|
| 652 | + if (! isset($allowable_formats[$format])) { |
|
| 653 | + throw new InvalidArgumentException( |
|
| 654 | + sprintf( |
|
| 655 | + esc_html__('The incoming argument (%1$s) must be one of the allowable formats: %2$s', 'event_espresso'), |
|
| 656 | + $format, |
|
| 657 | + implode(',', array_flip($allowable_formats)) |
|
| 658 | + ) |
|
| 659 | + ); |
|
| 660 | + } |
|
| 661 | + } |
|
| 663 | 662 | } |
| 664 | 663 | \ No newline at end of file |
@@ -11,14 +11,14 @@ |
||
| 11 | 11 | |
| 12 | 12 | |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * removes all tags which a WP Post wouldn't allow in its content normally |
|
| 16 | - * |
|
| 17 | - * @param string $value |
|
| 18 | - * @return string |
|
| 19 | - */ |
|
| 20 | - public function prepare_for_set($value) |
|
| 21 | - { |
|
| 22 | - return parent::prepare_for_set(wp_kses("$value", EEH_HTML::get_simple_tags())); |
|
| 23 | - } |
|
| 14 | + /** |
|
| 15 | + * removes all tags which a WP Post wouldn't allow in its content normally |
|
| 16 | + * |
|
| 17 | + * @param string $value |
|
| 18 | + * @return string |
|
| 19 | + */ |
|
| 20 | + public function prepare_for_set($value) |
|
| 21 | + { |
|
| 22 | + return parent::prepare_for_set(wp_kses("$value", EEH_HTML::get_simple_tags())); |
|
| 23 | + } |
|
| 24 | 24 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | <label for="ATT_fname"><?php _e('First Name', 'event_espresso'); ?><span class="denotes-required-spn">*</span></label> |
| 21 | 21 | </th> |
| 22 | 22 | <td> |
| 23 | - <div class="validation-notice-dv"><?php _e( 'The following is a required field', 'event_espresso' );?></div> |
|
| 23 | + <div class="validation-notice-dv"><?php _e('The following is a required field', 'event_espresso'); ?></div> |
|
| 24 | 24 | <input class="regular-text required" type="text" id="ATT_fname" name="ATT_fname" value="<?php echo $attendee->fname(); ?>"/><br/> |
| 25 | 25 | <p class="description"><?php _e('The registrant\'s given name. ( required value )', 'event_espresso'); ?></p> |
| 26 | 26 | </td> |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | <label for="ATT_lname"><?php _e('Last Name', 'event_espresso'); ?><span class="denotes-required-spn">*</span></label> |
| 32 | 32 | </th> |
| 33 | 33 | <td> |
| 34 | - <div class="validation-notice-dv"><?php _e( 'The following is a required field', 'event_espresso' );?></div> |
|
| 34 | + <div class="validation-notice-dv"><?php _e('The following is a required field', 'event_espresso'); ?></div> |
|
| 35 | 35 | <input class="regular-text required" type="text" id="ATT_lname" name="ATT_lname" value="<?php echo $attendee->lname(); ?>"/><br/> |
| 36 | 36 | <p class="description"><?php _e('The registrant\'s family name. ( required value )', 'event_espresso'); ?></p> |
| 37 | 37 | </td> |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | <label for="ATT_email"><?php _e('Email Address', 'event_espresso'); ?><span class="denotes-required-spn">*</span></label> |
| 43 | 43 | </th> |
| 44 | 44 | <td> |
| 45 | - <div class="validation-notice-dv"><?php _e( 'The following is a required field', 'event_espresso' );?></div> |
|
| 45 | + <div class="validation-notice-dv"><?php _e('The following is a required field', 'event_espresso'); ?></div> |
|
| 46 | 46 | <input class="regular-text required" type="text" id="ATT_email" name="ATT_email" value="<?php $attendee->f('ATT_email'); ?>"/><br/> |
| 47 | 47 | <p class="description"><?php _e('( required value )', 'event_espresso'); ?></p> |
| 48 | 48 | </td> |
@@ -109,8 +109,8 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | |
| 111 | 111 | |
| 112 | - <?php do_action( 'AHEE__attendee_details_main_meta_box__template__table_body_end',$attendee );?> |
|
| 112 | + <?php do_action('AHEE__attendee_details_main_meta_box__template__table_body_end', $attendee); ?> |
|
| 113 | 113 | </tbody> |
| 114 | 114 | </table> |
| 115 | - <?php do_action( 'AHEE__attendee_details_main_meta_box__template__after_table',$attendee );?> |
|
| 115 | + <?php do_action('AHEE__attendee_details_main_meta_box__template__after_table', $attendee); ?> |
|
| 116 | 116 | </div> |
| 117 | 117 | \ No newline at end of file |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | use EEH_DTT_Helper; |
| 10 | 10 | |
| 11 | 11 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 12 | - exit('No direct script access allowed'); |
|
| 12 | + exit('No direct script access allowed'); |
|
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | |
@@ -25,85 +25,85 @@ discard block |
||
| 25 | 25 | class Read |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @param WP_REST_Request $request |
|
| 30 | - * @param string $version |
|
| 31 | - * @return EE_Config|WP_Error |
|
| 32 | - */ |
|
| 33 | - public static function handleRequest(WP_REST_Request $request, $version) |
|
| 34 | - { |
|
| 35 | - $cap = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
|
| 36 | - if (EE_Capabilities::instance()->current_user_can($cap, 'read_over_api')) { |
|
| 37 | - return EE_Config::instance(); |
|
| 38 | - } else { |
|
| 39 | - return new WP_Error( |
|
| 40 | - 'cannot_read_config', |
|
| 41 | - sprintf( |
|
| 42 | - __( |
|
| 43 | - 'You do not have the necessary capabilities (%s) to read Event Espresso Configuration data', |
|
| 44 | - 'event_espresso' |
|
| 45 | - ), |
|
| 46 | - $cap |
|
| 47 | - ), |
|
| 48 | - array('status' => 403) |
|
| 49 | - ); |
|
| 50 | - } |
|
| 51 | - } |
|
| 28 | + /** |
|
| 29 | + * @param WP_REST_Request $request |
|
| 30 | + * @param string $version |
|
| 31 | + * @return EE_Config|WP_Error |
|
| 32 | + */ |
|
| 33 | + public static function handleRequest(WP_REST_Request $request, $version) |
|
| 34 | + { |
|
| 35 | + $cap = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
|
| 36 | + if (EE_Capabilities::instance()->current_user_can($cap, 'read_over_api')) { |
|
| 37 | + return EE_Config::instance(); |
|
| 38 | + } else { |
|
| 39 | + return new WP_Error( |
|
| 40 | + 'cannot_read_config', |
|
| 41 | + sprintf( |
|
| 42 | + __( |
|
| 43 | + 'You do not have the necessary capabilities (%s) to read Event Espresso Configuration data', |
|
| 44 | + 'event_espresso' |
|
| 45 | + ), |
|
| 46 | + $cap |
|
| 47 | + ), |
|
| 48 | + array('status' => 403) |
|
| 49 | + ); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | 53 | |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Handles the request for public site info |
|
| 57 | - * |
|
| 58 | - * @global $wp_json_basic_auth_success boolean set by the basic auth plugin, indicates if the |
|
| 59 | - * current user could be authenticated using basic auth data |
|
| 60 | - * @global $wp_json_basic_auth_received_data boolean set by the basic auth plugin, indicates if |
|
| 61 | - * basic auth data was somehow received |
|
| 62 | - * @param WP_REST_Request $request |
|
| 63 | - * @param string $version |
|
| 64 | - * @return array|WP_Error |
|
| 65 | - */ |
|
| 66 | - public static function handleRequestSiteInfo(WP_REST_Request $request, $version) |
|
| 67 | - { |
|
| 68 | - global $wp_json_basic_auth_success, $wp_json_basic_auth_received_data; |
|
| 69 | - $insecure_usage_of_basic_auth = apply_filters( |
|
| 70 | - // @codingStandardsIgnoreStart |
|
| 71 | - 'EventEspresso__core__libraries__rest_api__controllers__config__handle_request_site_info__insecure_usage_of_basic_auth', |
|
| 72 | - // @codingStandardsIgnoreEnd |
|
| 73 | - $wp_json_basic_auth_success && ! is_ssl(), |
|
| 74 | - $request |
|
| 75 | - ); |
|
| 76 | - if ($insecure_usage_of_basic_auth) { |
|
| 77 | - $warning = sprintf( |
|
| 78 | - esc_html__( |
|
| 79 | - // @codingStandardsIgnoreStart |
|
| 80 | - 'Notice: We strongly recommend installing an SSL Certificate on your website to keep your data secure. %1$sPlease see our recommendations.%2$s', |
|
| 81 | - // @codingStandardsIgnoreEnd |
|
| 82 | - 'event_espresso' |
|
| 83 | - ), |
|
| 84 | - '<a href="https://eventespresso.com/wiki/rest-api-security-recommendations/">', |
|
| 85 | - '</a>' |
|
| 86 | - ); |
|
| 87 | - } else { |
|
| 88 | - $warning = ''; |
|
| 89 | - } |
|
| 90 | - return apply_filters( |
|
| 91 | - 'FHEE__EventEspresso_core_libraries_rest_api_controllers_config__handleRequestSiteInfo__return_val', |
|
| 92 | - array( |
|
| 93 | - 'default_timezone' => array( |
|
| 94 | - 'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(), |
|
| 95 | - 'string' => get_option('timezone_string'), |
|
| 96 | - 'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(), |
|
| 97 | - ), |
|
| 98 | - 'default_currency' => EE_Config::instance()->currency, |
|
| 99 | - 'authentication' => array( |
|
| 100 | - 'received_basic_auth_data' => (bool)$wp_json_basic_auth_received_data, |
|
| 101 | - 'insecure_usage_of_basic_auth' => (bool)$insecure_usage_of_basic_auth, |
|
| 102 | - 'warning' => $warning |
|
| 103 | - ) |
|
| 104 | - ) |
|
| 105 | - ); |
|
| 106 | - } |
|
| 55 | + /** |
|
| 56 | + * Handles the request for public site info |
|
| 57 | + * |
|
| 58 | + * @global $wp_json_basic_auth_success boolean set by the basic auth plugin, indicates if the |
|
| 59 | + * current user could be authenticated using basic auth data |
|
| 60 | + * @global $wp_json_basic_auth_received_data boolean set by the basic auth plugin, indicates if |
|
| 61 | + * basic auth data was somehow received |
|
| 62 | + * @param WP_REST_Request $request |
|
| 63 | + * @param string $version |
|
| 64 | + * @return array|WP_Error |
|
| 65 | + */ |
|
| 66 | + public static function handleRequestSiteInfo(WP_REST_Request $request, $version) |
|
| 67 | + { |
|
| 68 | + global $wp_json_basic_auth_success, $wp_json_basic_auth_received_data; |
|
| 69 | + $insecure_usage_of_basic_auth = apply_filters( |
|
| 70 | + // @codingStandardsIgnoreStart |
|
| 71 | + 'EventEspresso__core__libraries__rest_api__controllers__config__handle_request_site_info__insecure_usage_of_basic_auth', |
|
| 72 | + // @codingStandardsIgnoreEnd |
|
| 73 | + $wp_json_basic_auth_success && ! is_ssl(), |
|
| 74 | + $request |
|
| 75 | + ); |
|
| 76 | + if ($insecure_usage_of_basic_auth) { |
|
| 77 | + $warning = sprintf( |
|
| 78 | + esc_html__( |
|
| 79 | + // @codingStandardsIgnoreStart |
|
| 80 | + 'Notice: We strongly recommend installing an SSL Certificate on your website to keep your data secure. %1$sPlease see our recommendations.%2$s', |
|
| 81 | + // @codingStandardsIgnoreEnd |
|
| 82 | + 'event_espresso' |
|
| 83 | + ), |
|
| 84 | + '<a href="https://eventespresso.com/wiki/rest-api-security-recommendations/">', |
|
| 85 | + '</a>' |
|
| 86 | + ); |
|
| 87 | + } else { |
|
| 88 | + $warning = ''; |
|
| 89 | + } |
|
| 90 | + return apply_filters( |
|
| 91 | + 'FHEE__EventEspresso_core_libraries_rest_api_controllers_config__handleRequestSiteInfo__return_val', |
|
| 92 | + array( |
|
| 93 | + 'default_timezone' => array( |
|
| 94 | + 'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(), |
|
| 95 | + 'string' => get_option('timezone_string'), |
|
| 96 | + 'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(), |
|
| 97 | + ), |
|
| 98 | + 'default_currency' => EE_Config::instance()->currency, |
|
| 99 | + 'authentication' => array( |
|
| 100 | + 'received_basic_auth_data' => (bool)$wp_json_basic_auth_received_data, |
|
| 101 | + 'insecure_usage_of_basic_auth' => (bool)$insecure_usage_of_basic_auth, |
|
| 102 | + 'warning' => $warning |
|
| 103 | + ) |
|
| 104 | + ) |
|
| 105 | + ); |
|
| 106 | + } |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | // End of file Read.php |
@@ -8,7 +8,7 @@ discard block |
||
| 8 | 8 | use EE_Restriction_Generator_Base; |
| 9 | 9 | use EEH_DTT_Helper; |
| 10 | 10 | |
| 11 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 11 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 12 | 12 | exit('No direct script access allowed'); |
| 13 | 13 | } |
| 14 | 14 | |
@@ -97,8 +97,8 @@ discard block |
||
| 97 | 97 | ), |
| 98 | 98 | 'default_currency' => EE_Config::instance()->currency, |
| 99 | 99 | 'authentication' => array( |
| 100 | - 'received_basic_auth_data' => (bool)$wp_json_basic_auth_received_data, |
|
| 101 | - 'insecure_usage_of_basic_auth' => (bool)$insecure_usage_of_basic_auth, |
|
| 100 | + 'received_basic_auth_data' => (bool) $wp_json_basic_auth_received_data, |
|
| 101 | + 'insecure_usage_of_basic_auth' => (bool) $insecure_usage_of_basic_auth, |
|
| 102 | 102 | 'warning' => $warning |
| 103 | 103 | ) |
| 104 | 104 | ) |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | /** |
| 5 | 5 | * Event Espresso |
@@ -23,670 +23,670 @@ discard block |
||
| 23 | 23 | class EE_Attendee extends EE_CPT_Base implements EEI_Contact, EEI_Address, EEI_Admin_Links, EEI_Attendee |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Sets some dynamic defaults |
|
| 28 | - * |
|
| 29 | - * @param array $fieldValues |
|
| 30 | - * @param bool $bydb |
|
| 31 | - * @param string $timezone |
|
| 32 | - * @param array $date_formats |
|
| 33 | - */ |
|
| 34 | - protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
|
| 35 | - { |
|
| 36 | - if (! isset($fieldValues['ATT_full_name'])) { |
|
| 37 | - $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
| 38 | - $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
|
| 39 | - $fieldValues['ATT_full_name'] = $fname . $lname; |
|
| 40 | - } |
|
| 41 | - if (! isset($fieldValues['ATT_slug'])) { |
|
| 42 | - // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
|
| 43 | - $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
|
| 44 | - } |
|
| 45 | - if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
| 46 | - $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
|
| 47 | - } |
|
| 48 | - parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @param array $props_n_values incoming values |
|
| 54 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 55 | - * used.) |
|
| 56 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 57 | - * date_format and the second value is the time format |
|
| 58 | - * @return EE_Attendee |
|
| 59 | - */ |
|
| 60 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 61 | - { |
|
| 62 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 63 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @param array $props_n_values incoming values from the database |
|
| 69 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 70 | - * the website will be used. |
|
| 71 | - * @return EE_Attendee |
|
| 72 | - */ |
|
| 73 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 74 | - { |
|
| 75 | - return new self($props_n_values, true, $timezone); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Set Attendee First Name |
|
| 81 | - * |
|
| 82 | - * @access public |
|
| 83 | - * @param string $fname |
|
| 84 | - */ |
|
| 85 | - public function set_fname($fname = '') |
|
| 86 | - { |
|
| 87 | - $this->set('ATT_fname', $fname); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Set Attendee Last Name |
|
| 93 | - * |
|
| 94 | - * @access public |
|
| 95 | - * @param string $lname |
|
| 96 | - */ |
|
| 97 | - public function set_lname($lname = '') |
|
| 98 | - { |
|
| 99 | - $this->set('ATT_lname', $lname); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Set Attendee Address |
|
| 105 | - * |
|
| 106 | - * @access public |
|
| 107 | - * @param string $address |
|
| 108 | - */ |
|
| 109 | - public function set_address($address = '') |
|
| 110 | - { |
|
| 111 | - $this->set('ATT_address', $address); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Set Attendee Address2 |
|
| 117 | - * |
|
| 118 | - * @access public |
|
| 119 | - * @param string $address2 |
|
| 120 | - */ |
|
| 121 | - public function set_address2($address2 = '') |
|
| 122 | - { |
|
| 123 | - $this->set('ATT_address2', $address2); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Set Attendee City |
|
| 129 | - * |
|
| 130 | - * @access public |
|
| 131 | - * @param string $city |
|
| 132 | - */ |
|
| 133 | - public function set_city($city = '') |
|
| 134 | - { |
|
| 135 | - $this->set('ATT_city', $city); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * Set Attendee State ID |
|
| 141 | - * |
|
| 142 | - * @access public |
|
| 143 | - * @param int $STA_ID |
|
| 144 | - */ |
|
| 145 | - public function set_state($STA_ID = 0) |
|
| 146 | - { |
|
| 147 | - $this->set('STA_ID', $STA_ID); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Set Attendee Country ISO Code |
|
| 153 | - * |
|
| 154 | - * @access public |
|
| 155 | - * @param string $CNT_ISO |
|
| 156 | - */ |
|
| 157 | - public function set_country($CNT_ISO = '') |
|
| 158 | - { |
|
| 159 | - $this->set('CNT_ISO', $CNT_ISO); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Set Attendee Zip/Postal Code |
|
| 165 | - * |
|
| 166 | - * @access public |
|
| 167 | - * @param string $zip |
|
| 168 | - */ |
|
| 169 | - public function set_zip($zip = '') |
|
| 170 | - { |
|
| 171 | - $this->set('ATT_zip', $zip); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Set Attendee Email Address |
|
| 177 | - * |
|
| 178 | - * @access public |
|
| 179 | - * @param string $email |
|
| 180 | - */ |
|
| 181 | - public function set_email($email = '') |
|
| 182 | - { |
|
| 183 | - $this->set('ATT_email', $email); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Set Attendee Phone |
|
| 189 | - * |
|
| 190 | - * @access public |
|
| 191 | - * @param string $phone |
|
| 192 | - */ |
|
| 193 | - public function set_phone($phone = '') |
|
| 194 | - { |
|
| 195 | - $this->set('ATT_phone', $phone); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * set deleted |
|
| 201 | - * |
|
| 202 | - * @access public |
|
| 203 | - * @param bool $ATT_deleted |
|
| 204 | - */ |
|
| 205 | - public function set_deleted($ATT_deleted = false) |
|
| 206 | - { |
|
| 207 | - $this->set('ATT_deleted', $ATT_deleted); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * Returns the value for the post_author id saved with the cpt |
|
| 213 | - * |
|
| 214 | - * @since 4.5.0 |
|
| 215 | - * @return int |
|
| 216 | - */ |
|
| 217 | - public function wp_user() |
|
| 218 | - { |
|
| 219 | - return $this->get('ATT_author'); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * get Attendee First Name |
|
| 225 | - * |
|
| 226 | - * @access public |
|
| 227 | - * @return string |
|
| 228 | - */ |
|
| 229 | - public function fname() |
|
| 230 | - { |
|
| 231 | - return $this->get('ATT_fname'); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * echoes out the attendee's first name |
|
| 237 | - * |
|
| 238 | - * @return void |
|
| 239 | - */ |
|
| 240 | - public function e_full_name() |
|
| 241 | - { |
|
| 242 | - echo $this->full_name(); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * Returns the first and last name concatenated together with a space. |
|
| 248 | - * |
|
| 249 | - * @param bool $apply_html_entities |
|
| 250 | - * @return string |
|
| 251 | - */ |
|
| 252 | - public function full_name($apply_html_entities = false) |
|
| 253 | - { |
|
| 254 | - $full_name = array( |
|
| 255 | - $this->fname(), |
|
| 256 | - $this->lname(), |
|
| 257 | - ); |
|
| 258 | - $full_name = array_filter($full_name); |
|
| 259 | - $full_name = implode(' ', $full_name); |
|
| 260 | - return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless |
|
| 266 | - * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this |
|
| 267 | - * attendee. |
|
| 268 | - * |
|
| 269 | - * @param bool $apply_html_entities |
|
| 270 | - * @return string |
|
| 271 | - */ |
|
| 272 | - public function ATT_full_name($apply_html_entities = false) |
|
| 273 | - { |
|
| 274 | - return $apply_html_entities |
|
| 275 | - ? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8') |
|
| 276 | - : $this->get('ATT_full_name'); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * get Attendee Last Name |
|
| 282 | - * |
|
| 283 | - * @access public |
|
| 284 | - * @return string |
|
| 285 | - */ |
|
| 286 | - public function lname() |
|
| 287 | - { |
|
| 288 | - return $this->get('ATT_lname'); |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * Gets the attendee's full address as an array so client code can decide hwo to display it |
|
| 294 | - * |
|
| 295 | - * @return array numerically indexed, with each part of the address that is known. |
|
| 296 | - * Eg, if the user only responded to state and country, |
|
| 297 | - * it would be array(0=>'Alabama',1=>'USA') |
|
| 298 | - * @return array |
|
| 299 | - */ |
|
| 300 | - public function full_address_as_array() |
|
| 301 | - { |
|
| 302 | - $full_address_array = array(); |
|
| 303 | - $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
|
| 304 | - foreach ($initial_address_fields as $address_field_name) { |
|
| 305 | - $address_fields_value = $this->get($address_field_name); |
|
| 306 | - if (! empty($address_fields_value)) { |
|
| 307 | - $full_address_array[] = $address_fields_value; |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - //now handle state and country |
|
| 311 | - $state_obj = $this->state_obj(); |
|
| 312 | - if (! empty($state_obj)) { |
|
| 313 | - $full_address_array[] = $state_obj->name(); |
|
| 314 | - } |
|
| 315 | - $country_obj = $this->country_obj(); |
|
| 316 | - if (! empty($country_obj)) { |
|
| 317 | - $full_address_array[] = $country_obj->name(); |
|
| 318 | - } |
|
| 319 | - //lastly get the xip |
|
| 320 | - $zip_value = $this->zip(); |
|
| 321 | - if (! empty($zip_value)) { |
|
| 322 | - $full_address_array[] = $zip_value; |
|
| 323 | - } |
|
| 324 | - return $full_address_array; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * get Attendee Address |
|
| 330 | - * |
|
| 331 | - * @return string |
|
| 332 | - */ |
|
| 333 | - public function address() |
|
| 334 | - { |
|
| 335 | - return $this->get('ATT_address'); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * get Attendee Address2 |
|
| 341 | - * |
|
| 342 | - * @return string |
|
| 343 | - */ |
|
| 344 | - public function address2() |
|
| 345 | - { |
|
| 346 | - return $this->get('ATT_address2'); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * get Attendee City |
|
| 352 | - * |
|
| 353 | - * @return string |
|
| 354 | - */ |
|
| 355 | - public function city() |
|
| 356 | - { |
|
| 357 | - return $this->get('ATT_city'); |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * get Attendee State ID |
|
| 363 | - * |
|
| 364 | - * @return string |
|
| 365 | - */ |
|
| 366 | - public function state_ID() |
|
| 367 | - { |
|
| 368 | - return $this->get('STA_ID'); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * @return string |
|
| 374 | - */ |
|
| 375 | - public function state_abbrev() |
|
| 376 | - { |
|
| 377 | - return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : ''; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * Gets the state set to this attendee |
|
| 383 | - * |
|
| 384 | - * @return EE_State |
|
| 385 | - */ |
|
| 386 | - public function state_obj() |
|
| 387 | - { |
|
| 388 | - return $this->get_first_related('State'); |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * Returns the state's name, otherwise 'Unknown' |
|
| 394 | - * |
|
| 395 | - * @return string |
|
| 396 | - */ |
|
| 397 | - public function state_name() |
|
| 398 | - { |
|
| 399 | - if ($this->state_obj()) { |
|
| 400 | - return $this->state_obj()->name(); |
|
| 401 | - } else { |
|
| 402 | - return ''; |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * either displays the state abbreviation or the state name, as determined |
|
| 409 | - * by the "FHEE__EEI_Address__state__use_abbreviation" filter. |
|
| 410 | - * defaults to abbreviation |
|
| 411 | - * |
|
| 412 | - * @return string |
|
| 413 | - */ |
|
| 414 | - public function state() |
|
| 415 | - { |
|
| 416 | - if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
| 417 | - return $this->state_abbrev(); |
|
| 418 | - } else { |
|
| 419 | - return $this->state_name(); |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * get Attendee Country ISO Code |
|
| 426 | - * |
|
| 427 | - * @return string |
|
| 428 | - */ |
|
| 429 | - public function country_ID() |
|
| 430 | - { |
|
| 431 | - return $this->get('CNT_ISO'); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * Gets country set for this attendee |
|
| 437 | - * |
|
| 438 | - * @return EE_Country |
|
| 439 | - */ |
|
| 440 | - public function country_obj() |
|
| 441 | - { |
|
| 442 | - return $this->get_first_related('Country'); |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - |
|
| 446 | - /** |
|
| 447 | - * Returns the country's name if known, otherwise 'Unknown' |
|
| 448 | - * |
|
| 449 | - * @return string |
|
| 450 | - */ |
|
| 451 | - public function country_name() |
|
| 452 | - { |
|
| 453 | - if ($this->country_obj()) { |
|
| 454 | - return $this->country_obj()->name(); |
|
| 455 | - } else { |
|
| 456 | - return ''; |
|
| 457 | - } |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - |
|
| 461 | - /** |
|
| 462 | - * either displays the country ISO2 code or the country name, as determined |
|
| 463 | - * by the "FHEE__EEI_Address__country__use_abbreviation" filter. |
|
| 464 | - * defaults to abbreviation |
|
| 465 | - * |
|
| 466 | - * @return string |
|
| 467 | - */ |
|
| 468 | - public function country() |
|
| 469 | - { |
|
| 470 | - if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
| 471 | - return $this->country_ID(); |
|
| 472 | - } else { |
|
| 473 | - return $this->country_name(); |
|
| 474 | - } |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * get Attendee Zip/Postal Code |
|
| 480 | - * |
|
| 481 | - * @return string |
|
| 482 | - */ |
|
| 483 | - public function zip() |
|
| 484 | - { |
|
| 485 | - return $this->get('ATT_zip'); |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * get Attendee Email Address |
|
| 491 | - * |
|
| 492 | - * @return string |
|
| 493 | - */ |
|
| 494 | - public function email() |
|
| 495 | - { |
|
| 496 | - return $this->get('ATT_email'); |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * get Attendee Phone # |
|
| 502 | - * |
|
| 503 | - * @return string |
|
| 504 | - */ |
|
| 505 | - public function phone() |
|
| 506 | - { |
|
| 507 | - return $this->get('ATT_phone'); |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * get deleted |
|
| 513 | - * |
|
| 514 | - * @return bool |
|
| 515 | - */ |
|
| 516 | - public function deleted() |
|
| 517 | - { |
|
| 518 | - return $this->get('ATT_deleted'); |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - |
|
| 522 | - /** |
|
| 523 | - * Gets registrations of this attendee |
|
| 524 | - * |
|
| 525 | - * @param array $query_params |
|
| 526 | - * @return EE_Registration[] |
|
| 527 | - */ |
|
| 528 | - public function get_registrations($query_params = array()) |
|
| 529 | - { |
|
| 530 | - return $this->get_many_related('Registration', $query_params); |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - |
|
| 534 | - /** |
|
| 535 | - * Gets the most recent registration of this attendee |
|
| 536 | - * |
|
| 537 | - * @return EE_Registration |
|
| 538 | - */ |
|
| 539 | - public function get_most_recent_registration() |
|
| 540 | - { |
|
| 541 | - return $this->get_first_related('Registration', |
|
| 542 | - array('order_by' => array('REG_date' => 'DESC'))); //null, 'REG_date', 'DESC', '=', 'OBJECT_K'); |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Gets the most recent registration for this attend at this event |
|
| 548 | - * |
|
| 549 | - * @param int $event_id |
|
| 550 | - * @return EE_Registration |
|
| 551 | - */ |
|
| 552 | - public function get_most_recent_registration_for_event($event_id) |
|
| 553 | - { |
|
| 554 | - return $this->get_first_related('Registration', |
|
| 555 | - array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC')));//, '=', 'OBJECT_K' ); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - /** |
|
| 560 | - * returns any events attached to this attendee ($_Event property); |
|
| 561 | - * |
|
| 562 | - * @return array |
|
| 563 | - */ |
|
| 564 | - public function events() |
|
| 565 | - { |
|
| 566 | - return $this->get_many_related('Event'); |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - |
|
| 570 | - /** |
|
| 571 | - * Gets the billing info array where keys match espresso_reg_page_billing_inputs(), |
|
| 572 | - * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was |
|
| 573 | - * used to save the billing info |
|
| 574 | - * |
|
| 575 | - * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class |
|
| 576 | - * @return EE_Form_Section_Proper|null |
|
| 577 | - */ |
|
| 578 | - public function billing_info_for_payment_method($payment_method) |
|
| 579 | - { |
|
| 580 | - $pm_type = $payment_method->type_obj(); |
|
| 581 | - if (! $pm_type instanceof EE_PMT_Base) { |
|
| 582 | - return null; |
|
| 583 | - } |
|
| 584 | - $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
|
| 585 | - if (! $billing_info) { |
|
| 586 | - return null; |
|
| 587 | - } |
|
| 588 | - $billing_form = $pm_type->billing_form(); |
|
| 589 | - if ($billing_form instanceof EE_Form_Section_Proper) { |
|
| 590 | - $billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false); |
|
| 591 | - } |
|
| 592 | - return $billing_form; |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * Gets the postmeta key that holds this attendee's billing info for the |
|
| 598 | - * specified payment method |
|
| 599 | - * |
|
| 600 | - * @param EE_Payment_Method $payment_method |
|
| 601 | - * @return string |
|
| 602 | - */ |
|
| 603 | - public function get_billing_info_postmeta_name($payment_method) |
|
| 604 | - { |
|
| 605 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 606 | - return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
| 607 | - } else { |
|
| 608 | - return null; |
|
| 609 | - } |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - |
|
| 613 | - /** |
|
| 614 | - * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to |
|
| 615 | - * retrieve it |
|
| 616 | - * |
|
| 617 | - * @param EE_Billing_Attendee_Info_Form $billing_form |
|
| 618 | - * @param EE_Payment_Method $payment_method |
|
| 619 | - * @return boolean |
|
| 620 | - */ |
|
| 621 | - public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
|
| 622 | - { |
|
| 623 | - if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
| 624 | - EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso')); |
|
| 625 | - return false; |
|
| 626 | - } |
|
| 627 | - $billing_form->clean_sensitive_data(); |
|
| 628 | - return update_post_meta($this->ID(), $this->get_billing_info_postmeta_name($payment_method), |
|
| 629 | - $billing_form->input_values(true)); |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - |
|
| 633 | - /** |
|
| 634 | - * Return the link to the admin details for the object. |
|
| 635 | - * |
|
| 636 | - * @return string |
|
| 637 | - */ |
|
| 638 | - public function get_admin_details_link() |
|
| 639 | - { |
|
| 640 | - return $this->get_admin_edit_link(); |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - |
|
| 644 | - /** |
|
| 645 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 646 | - * |
|
| 647 | - * @return string |
|
| 648 | - */ |
|
| 649 | - public function get_admin_edit_link() |
|
| 650 | - { |
|
| 651 | - EE_Registry::instance()->load_helper('URL'); |
|
| 652 | - return EEH_URL::add_query_args_and_nonce( |
|
| 653 | - array( |
|
| 654 | - 'page' => 'espresso_registrations', |
|
| 655 | - 'action' => 'edit_attendee', |
|
| 656 | - 'post' => $this->ID(), |
|
| 657 | - ), |
|
| 658 | - admin_url('admin.php') |
|
| 659 | - ); |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - |
|
| 663 | - /** |
|
| 664 | - * Returns the link to a settings page for the object. |
|
| 665 | - * |
|
| 666 | - * @return string |
|
| 667 | - */ |
|
| 668 | - public function get_admin_settings_link() |
|
| 669 | - { |
|
| 670 | - return $this->get_admin_edit_link(); |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - |
|
| 674 | - /** |
|
| 675 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 676 | - * |
|
| 677 | - * @return string |
|
| 678 | - */ |
|
| 679 | - public function get_admin_overview_link() |
|
| 680 | - { |
|
| 681 | - EE_Registry::instance()->load_helper('URL'); |
|
| 682 | - return EEH_URL::add_query_args_and_nonce( |
|
| 683 | - array( |
|
| 684 | - 'page' => 'espresso_registrations', |
|
| 685 | - 'action' => 'contact_list', |
|
| 686 | - ), |
|
| 687 | - admin_url('admin.php') |
|
| 688 | - ); |
|
| 689 | - } |
|
| 26 | + /** |
|
| 27 | + * Sets some dynamic defaults |
|
| 28 | + * |
|
| 29 | + * @param array $fieldValues |
|
| 30 | + * @param bool $bydb |
|
| 31 | + * @param string $timezone |
|
| 32 | + * @param array $date_formats |
|
| 33 | + */ |
|
| 34 | + protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
|
| 35 | + { |
|
| 36 | + if (! isset($fieldValues['ATT_full_name'])) { |
|
| 37 | + $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
| 38 | + $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
|
| 39 | + $fieldValues['ATT_full_name'] = $fname . $lname; |
|
| 40 | + } |
|
| 41 | + if (! isset($fieldValues['ATT_slug'])) { |
|
| 42 | + // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
|
| 43 | + $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
|
| 44 | + } |
|
| 45 | + if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
| 46 | + $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
|
| 47 | + } |
|
| 48 | + parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @param array $props_n_values incoming values |
|
| 54 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 55 | + * used.) |
|
| 56 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 57 | + * date_format and the second value is the time format |
|
| 58 | + * @return EE_Attendee |
|
| 59 | + */ |
|
| 60 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 61 | + { |
|
| 62 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 63 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @param array $props_n_values incoming values from the database |
|
| 69 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 70 | + * the website will be used. |
|
| 71 | + * @return EE_Attendee |
|
| 72 | + */ |
|
| 73 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 74 | + { |
|
| 75 | + return new self($props_n_values, true, $timezone); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Set Attendee First Name |
|
| 81 | + * |
|
| 82 | + * @access public |
|
| 83 | + * @param string $fname |
|
| 84 | + */ |
|
| 85 | + public function set_fname($fname = '') |
|
| 86 | + { |
|
| 87 | + $this->set('ATT_fname', $fname); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Set Attendee Last Name |
|
| 93 | + * |
|
| 94 | + * @access public |
|
| 95 | + * @param string $lname |
|
| 96 | + */ |
|
| 97 | + public function set_lname($lname = '') |
|
| 98 | + { |
|
| 99 | + $this->set('ATT_lname', $lname); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Set Attendee Address |
|
| 105 | + * |
|
| 106 | + * @access public |
|
| 107 | + * @param string $address |
|
| 108 | + */ |
|
| 109 | + public function set_address($address = '') |
|
| 110 | + { |
|
| 111 | + $this->set('ATT_address', $address); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Set Attendee Address2 |
|
| 117 | + * |
|
| 118 | + * @access public |
|
| 119 | + * @param string $address2 |
|
| 120 | + */ |
|
| 121 | + public function set_address2($address2 = '') |
|
| 122 | + { |
|
| 123 | + $this->set('ATT_address2', $address2); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Set Attendee City |
|
| 129 | + * |
|
| 130 | + * @access public |
|
| 131 | + * @param string $city |
|
| 132 | + */ |
|
| 133 | + public function set_city($city = '') |
|
| 134 | + { |
|
| 135 | + $this->set('ATT_city', $city); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * Set Attendee State ID |
|
| 141 | + * |
|
| 142 | + * @access public |
|
| 143 | + * @param int $STA_ID |
|
| 144 | + */ |
|
| 145 | + public function set_state($STA_ID = 0) |
|
| 146 | + { |
|
| 147 | + $this->set('STA_ID', $STA_ID); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Set Attendee Country ISO Code |
|
| 153 | + * |
|
| 154 | + * @access public |
|
| 155 | + * @param string $CNT_ISO |
|
| 156 | + */ |
|
| 157 | + public function set_country($CNT_ISO = '') |
|
| 158 | + { |
|
| 159 | + $this->set('CNT_ISO', $CNT_ISO); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Set Attendee Zip/Postal Code |
|
| 165 | + * |
|
| 166 | + * @access public |
|
| 167 | + * @param string $zip |
|
| 168 | + */ |
|
| 169 | + public function set_zip($zip = '') |
|
| 170 | + { |
|
| 171 | + $this->set('ATT_zip', $zip); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Set Attendee Email Address |
|
| 177 | + * |
|
| 178 | + * @access public |
|
| 179 | + * @param string $email |
|
| 180 | + */ |
|
| 181 | + public function set_email($email = '') |
|
| 182 | + { |
|
| 183 | + $this->set('ATT_email', $email); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Set Attendee Phone |
|
| 189 | + * |
|
| 190 | + * @access public |
|
| 191 | + * @param string $phone |
|
| 192 | + */ |
|
| 193 | + public function set_phone($phone = '') |
|
| 194 | + { |
|
| 195 | + $this->set('ATT_phone', $phone); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * set deleted |
|
| 201 | + * |
|
| 202 | + * @access public |
|
| 203 | + * @param bool $ATT_deleted |
|
| 204 | + */ |
|
| 205 | + public function set_deleted($ATT_deleted = false) |
|
| 206 | + { |
|
| 207 | + $this->set('ATT_deleted', $ATT_deleted); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * Returns the value for the post_author id saved with the cpt |
|
| 213 | + * |
|
| 214 | + * @since 4.5.0 |
|
| 215 | + * @return int |
|
| 216 | + */ |
|
| 217 | + public function wp_user() |
|
| 218 | + { |
|
| 219 | + return $this->get('ATT_author'); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * get Attendee First Name |
|
| 225 | + * |
|
| 226 | + * @access public |
|
| 227 | + * @return string |
|
| 228 | + */ |
|
| 229 | + public function fname() |
|
| 230 | + { |
|
| 231 | + return $this->get('ATT_fname'); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * echoes out the attendee's first name |
|
| 237 | + * |
|
| 238 | + * @return void |
|
| 239 | + */ |
|
| 240 | + public function e_full_name() |
|
| 241 | + { |
|
| 242 | + echo $this->full_name(); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * Returns the first and last name concatenated together with a space. |
|
| 248 | + * |
|
| 249 | + * @param bool $apply_html_entities |
|
| 250 | + * @return string |
|
| 251 | + */ |
|
| 252 | + public function full_name($apply_html_entities = false) |
|
| 253 | + { |
|
| 254 | + $full_name = array( |
|
| 255 | + $this->fname(), |
|
| 256 | + $this->lname(), |
|
| 257 | + ); |
|
| 258 | + $full_name = array_filter($full_name); |
|
| 259 | + $full_name = implode(' ', $full_name); |
|
| 260 | + return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless |
|
| 266 | + * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this |
|
| 267 | + * attendee. |
|
| 268 | + * |
|
| 269 | + * @param bool $apply_html_entities |
|
| 270 | + * @return string |
|
| 271 | + */ |
|
| 272 | + public function ATT_full_name($apply_html_entities = false) |
|
| 273 | + { |
|
| 274 | + return $apply_html_entities |
|
| 275 | + ? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8') |
|
| 276 | + : $this->get('ATT_full_name'); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * get Attendee Last Name |
|
| 282 | + * |
|
| 283 | + * @access public |
|
| 284 | + * @return string |
|
| 285 | + */ |
|
| 286 | + public function lname() |
|
| 287 | + { |
|
| 288 | + return $this->get('ATT_lname'); |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * Gets the attendee's full address as an array so client code can decide hwo to display it |
|
| 294 | + * |
|
| 295 | + * @return array numerically indexed, with each part of the address that is known. |
|
| 296 | + * Eg, if the user only responded to state and country, |
|
| 297 | + * it would be array(0=>'Alabama',1=>'USA') |
|
| 298 | + * @return array |
|
| 299 | + */ |
|
| 300 | + public function full_address_as_array() |
|
| 301 | + { |
|
| 302 | + $full_address_array = array(); |
|
| 303 | + $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
|
| 304 | + foreach ($initial_address_fields as $address_field_name) { |
|
| 305 | + $address_fields_value = $this->get($address_field_name); |
|
| 306 | + if (! empty($address_fields_value)) { |
|
| 307 | + $full_address_array[] = $address_fields_value; |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + //now handle state and country |
|
| 311 | + $state_obj = $this->state_obj(); |
|
| 312 | + if (! empty($state_obj)) { |
|
| 313 | + $full_address_array[] = $state_obj->name(); |
|
| 314 | + } |
|
| 315 | + $country_obj = $this->country_obj(); |
|
| 316 | + if (! empty($country_obj)) { |
|
| 317 | + $full_address_array[] = $country_obj->name(); |
|
| 318 | + } |
|
| 319 | + //lastly get the xip |
|
| 320 | + $zip_value = $this->zip(); |
|
| 321 | + if (! empty($zip_value)) { |
|
| 322 | + $full_address_array[] = $zip_value; |
|
| 323 | + } |
|
| 324 | + return $full_address_array; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * get Attendee Address |
|
| 330 | + * |
|
| 331 | + * @return string |
|
| 332 | + */ |
|
| 333 | + public function address() |
|
| 334 | + { |
|
| 335 | + return $this->get('ATT_address'); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * get Attendee Address2 |
|
| 341 | + * |
|
| 342 | + * @return string |
|
| 343 | + */ |
|
| 344 | + public function address2() |
|
| 345 | + { |
|
| 346 | + return $this->get('ATT_address2'); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * get Attendee City |
|
| 352 | + * |
|
| 353 | + * @return string |
|
| 354 | + */ |
|
| 355 | + public function city() |
|
| 356 | + { |
|
| 357 | + return $this->get('ATT_city'); |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * get Attendee State ID |
|
| 363 | + * |
|
| 364 | + * @return string |
|
| 365 | + */ |
|
| 366 | + public function state_ID() |
|
| 367 | + { |
|
| 368 | + return $this->get('STA_ID'); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * @return string |
|
| 374 | + */ |
|
| 375 | + public function state_abbrev() |
|
| 376 | + { |
|
| 377 | + return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : ''; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * Gets the state set to this attendee |
|
| 383 | + * |
|
| 384 | + * @return EE_State |
|
| 385 | + */ |
|
| 386 | + public function state_obj() |
|
| 387 | + { |
|
| 388 | + return $this->get_first_related('State'); |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * Returns the state's name, otherwise 'Unknown' |
|
| 394 | + * |
|
| 395 | + * @return string |
|
| 396 | + */ |
|
| 397 | + public function state_name() |
|
| 398 | + { |
|
| 399 | + if ($this->state_obj()) { |
|
| 400 | + return $this->state_obj()->name(); |
|
| 401 | + } else { |
|
| 402 | + return ''; |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * either displays the state abbreviation or the state name, as determined |
|
| 409 | + * by the "FHEE__EEI_Address__state__use_abbreviation" filter. |
|
| 410 | + * defaults to abbreviation |
|
| 411 | + * |
|
| 412 | + * @return string |
|
| 413 | + */ |
|
| 414 | + public function state() |
|
| 415 | + { |
|
| 416 | + if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
| 417 | + return $this->state_abbrev(); |
|
| 418 | + } else { |
|
| 419 | + return $this->state_name(); |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * get Attendee Country ISO Code |
|
| 426 | + * |
|
| 427 | + * @return string |
|
| 428 | + */ |
|
| 429 | + public function country_ID() |
|
| 430 | + { |
|
| 431 | + return $this->get('CNT_ISO'); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * Gets country set for this attendee |
|
| 437 | + * |
|
| 438 | + * @return EE_Country |
|
| 439 | + */ |
|
| 440 | + public function country_obj() |
|
| 441 | + { |
|
| 442 | + return $this->get_first_related('Country'); |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + |
|
| 446 | + /** |
|
| 447 | + * Returns the country's name if known, otherwise 'Unknown' |
|
| 448 | + * |
|
| 449 | + * @return string |
|
| 450 | + */ |
|
| 451 | + public function country_name() |
|
| 452 | + { |
|
| 453 | + if ($this->country_obj()) { |
|
| 454 | + return $this->country_obj()->name(); |
|
| 455 | + } else { |
|
| 456 | + return ''; |
|
| 457 | + } |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * either displays the country ISO2 code or the country name, as determined |
|
| 463 | + * by the "FHEE__EEI_Address__country__use_abbreviation" filter. |
|
| 464 | + * defaults to abbreviation |
|
| 465 | + * |
|
| 466 | + * @return string |
|
| 467 | + */ |
|
| 468 | + public function country() |
|
| 469 | + { |
|
| 470 | + if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
| 471 | + return $this->country_ID(); |
|
| 472 | + } else { |
|
| 473 | + return $this->country_name(); |
|
| 474 | + } |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * get Attendee Zip/Postal Code |
|
| 480 | + * |
|
| 481 | + * @return string |
|
| 482 | + */ |
|
| 483 | + public function zip() |
|
| 484 | + { |
|
| 485 | + return $this->get('ATT_zip'); |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * get Attendee Email Address |
|
| 491 | + * |
|
| 492 | + * @return string |
|
| 493 | + */ |
|
| 494 | + public function email() |
|
| 495 | + { |
|
| 496 | + return $this->get('ATT_email'); |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * get Attendee Phone # |
|
| 502 | + * |
|
| 503 | + * @return string |
|
| 504 | + */ |
|
| 505 | + public function phone() |
|
| 506 | + { |
|
| 507 | + return $this->get('ATT_phone'); |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * get deleted |
|
| 513 | + * |
|
| 514 | + * @return bool |
|
| 515 | + */ |
|
| 516 | + public function deleted() |
|
| 517 | + { |
|
| 518 | + return $this->get('ATT_deleted'); |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + |
|
| 522 | + /** |
|
| 523 | + * Gets registrations of this attendee |
|
| 524 | + * |
|
| 525 | + * @param array $query_params |
|
| 526 | + * @return EE_Registration[] |
|
| 527 | + */ |
|
| 528 | + public function get_registrations($query_params = array()) |
|
| 529 | + { |
|
| 530 | + return $this->get_many_related('Registration', $query_params); |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + |
|
| 534 | + /** |
|
| 535 | + * Gets the most recent registration of this attendee |
|
| 536 | + * |
|
| 537 | + * @return EE_Registration |
|
| 538 | + */ |
|
| 539 | + public function get_most_recent_registration() |
|
| 540 | + { |
|
| 541 | + return $this->get_first_related('Registration', |
|
| 542 | + array('order_by' => array('REG_date' => 'DESC'))); //null, 'REG_date', 'DESC', '=', 'OBJECT_K'); |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Gets the most recent registration for this attend at this event |
|
| 548 | + * |
|
| 549 | + * @param int $event_id |
|
| 550 | + * @return EE_Registration |
|
| 551 | + */ |
|
| 552 | + public function get_most_recent_registration_for_event($event_id) |
|
| 553 | + { |
|
| 554 | + return $this->get_first_related('Registration', |
|
| 555 | + array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC')));//, '=', 'OBJECT_K' ); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * returns any events attached to this attendee ($_Event property); |
|
| 561 | + * |
|
| 562 | + * @return array |
|
| 563 | + */ |
|
| 564 | + public function events() |
|
| 565 | + { |
|
| 566 | + return $this->get_many_related('Event'); |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + |
|
| 570 | + /** |
|
| 571 | + * Gets the billing info array where keys match espresso_reg_page_billing_inputs(), |
|
| 572 | + * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was |
|
| 573 | + * used to save the billing info |
|
| 574 | + * |
|
| 575 | + * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class |
|
| 576 | + * @return EE_Form_Section_Proper|null |
|
| 577 | + */ |
|
| 578 | + public function billing_info_for_payment_method($payment_method) |
|
| 579 | + { |
|
| 580 | + $pm_type = $payment_method->type_obj(); |
|
| 581 | + if (! $pm_type instanceof EE_PMT_Base) { |
|
| 582 | + return null; |
|
| 583 | + } |
|
| 584 | + $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
|
| 585 | + if (! $billing_info) { |
|
| 586 | + return null; |
|
| 587 | + } |
|
| 588 | + $billing_form = $pm_type->billing_form(); |
|
| 589 | + if ($billing_form instanceof EE_Form_Section_Proper) { |
|
| 590 | + $billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false); |
|
| 591 | + } |
|
| 592 | + return $billing_form; |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * Gets the postmeta key that holds this attendee's billing info for the |
|
| 598 | + * specified payment method |
|
| 599 | + * |
|
| 600 | + * @param EE_Payment_Method $payment_method |
|
| 601 | + * @return string |
|
| 602 | + */ |
|
| 603 | + public function get_billing_info_postmeta_name($payment_method) |
|
| 604 | + { |
|
| 605 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 606 | + return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
| 607 | + } else { |
|
| 608 | + return null; |
|
| 609 | + } |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + |
|
| 613 | + /** |
|
| 614 | + * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to |
|
| 615 | + * retrieve it |
|
| 616 | + * |
|
| 617 | + * @param EE_Billing_Attendee_Info_Form $billing_form |
|
| 618 | + * @param EE_Payment_Method $payment_method |
|
| 619 | + * @return boolean |
|
| 620 | + */ |
|
| 621 | + public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
|
| 622 | + { |
|
| 623 | + if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
| 624 | + EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso')); |
|
| 625 | + return false; |
|
| 626 | + } |
|
| 627 | + $billing_form->clean_sensitive_data(); |
|
| 628 | + return update_post_meta($this->ID(), $this->get_billing_info_postmeta_name($payment_method), |
|
| 629 | + $billing_form->input_values(true)); |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + |
|
| 633 | + /** |
|
| 634 | + * Return the link to the admin details for the object. |
|
| 635 | + * |
|
| 636 | + * @return string |
|
| 637 | + */ |
|
| 638 | + public function get_admin_details_link() |
|
| 639 | + { |
|
| 640 | + return $this->get_admin_edit_link(); |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + |
|
| 644 | + /** |
|
| 645 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 646 | + * |
|
| 647 | + * @return string |
|
| 648 | + */ |
|
| 649 | + public function get_admin_edit_link() |
|
| 650 | + { |
|
| 651 | + EE_Registry::instance()->load_helper('URL'); |
|
| 652 | + return EEH_URL::add_query_args_and_nonce( |
|
| 653 | + array( |
|
| 654 | + 'page' => 'espresso_registrations', |
|
| 655 | + 'action' => 'edit_attendee', |
|
| 656 | + 'post' => $this->ID(), |
|
| 657 | + ), |
|
| 658 | + admin_url('admin.php') |
|
| 659 | + ); |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + |
|
| 663 | + /** |
|
| 664 | + * Returns the link to a settings page for the object. |
|
| 665 | + * |
|
| 666 | + * @return string |
|
| 667 | + */ |
|
| 668 | + public function get_admin_settings_link() |
|
| 669 | + { |
|
| 670 | + return $this->get_admin_edit_link(); |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + |
|
| 674 | + /** |
|
| 675 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 676 | + * |
|
| 677 | + * @return string |
|
| 678 | + */ |
|
| 679 | + public function get_admin_overview_link() |
|
| 680 | + { |
|
| 681 | + EE_Registry::instance()->load_helper('URL'); |
|
| 682 | + return EEH_URL::add_query_args_and_nonce( |
|
| 683 | + array( |
|
| 684 | + 'page' => 'espresso_registrations', |
|
| 685 | + 'action' => 'contact_list', |
|
| 686 | + ), |
|
| 687 | + admin_url('admin.php') |
|
| 688 | + ); |
|
| 689 | + } |
|
| 690 | 690 | |
| 691 | 691 | |
| 692 | 692 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | /** |
@@ -13,93 +13,93 @@ discard block |
||
| 13 | 13 | class EE_WP_User extends EE_Base_Class implements EEI_Admin_Links |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @var WP_User |
|
| 18 | - */ |
|
| 19 | - protected $_wp_user_obj; |
|
| 16 | + /** |
|
| 17 | + * @var WP_User |
|
| 18 | + */ |
|
| 19 | + protected $_wp_user_obj; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @param array $props_n_values |
|
| 23 | - * @return EE_WP_User|mixed |
|
| 24 | - */ |
|
| 25 | - public static function new_instance($props_n_values = array()) |
|
| 26 | - { |
|
| 27 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 28 | - return $has_object ? $has_object : new self($props_n_values); |
|
| 29 | - } |
|
| 21 | + /** |
|
| 22 | + * @param array $props_n_values |
|
| 23 | + * @return EE_WP_User|mixed |
|
| 24 | + */ |
|
| 25 | + public static function new_instance($props_n_values = array()) |
|
| 26 | + { |
|
| 27 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
| 28 | + return $has_object ? $has_object : new self($props_n_values); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @param array $props_n_values |
|
| 34 | - * @return EE_WP_User |
|
| 35 | - */ |
|
| 36 | - public static function new_instance_from_db($props_n_values = array()) |
|
| 37 | - { |
|
| 38 | - return new self($props_n_values, true); |
|
| 39 | - } |
|
| 32 | + /** |
|
| 33 | + * @param array $props_n_values |
|
| 34 | + * @return EE_WP_User |
|
| 35 | + */ |
|
| 36 | + public static function new_instance_from_db($props_n_values = array()) |
|
| 37 | + { |
|
| 38 | + return new self($props_n_values, true); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Return a normal WP_User object (caches the object for future calls) |
|
| 43 | - * |
|
| 44 | - * @return WP_User |
|
| 45 | - */ |
|
| 46 | - public function wp_user_obj() |
|
| 47 | - { |
|
| 48 | - if (! $this->_wp_user_obj) { |
|
| 49 | - $this->_wp_user_obj = get_user_by('ID', $this->ID()); |
|
| 50 | - } |
|
| 51 | - return $this->_wp_user_obj; |
|
| 52 | - } |
|
| 41 | + /** |
|
| 42 | + * Return a normal WP_User object (caches the object for future calls) |
|
| 43 | + * |
|
| 44 | + * @return WP_User |
|
| 45 | + */ |
|
| 46 | + public function wp_user_obj() |
|
| 47 | + { |
|
| 48 | + if (! $this->_wp_user_obj) { |
|
| 49 | + $this->_wp_user_obj = get_user_by('ID', $this->ID()); |
|
| 50 | + } |
|
| 51 | + return $this->_wp_user_obj; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Return the link to the admin details for the object. |
|
| 56 | - * |
|
| 57 | - * @return string |
|
| 58 | - */ |
|
| 59 | - public function get_admin_details_link() |
|
| 60 | - { |
|
| 61 | - return $this->get_admin_edit_link(); |
|
| 62 | - } |
|
| 54 | + /** |
|
| 55 | + * Return the link to the admin details for the object. |
|
| 56 | + * |
|
| 57 | + * @return string |
|
| 58 | + */ |
|
| 59 | + public function get_admin_details_link() |
|
| 60 | + { |
|
| 61 | + return $this->get_admin_edit_link(); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 66 | - * |
|
| 67 | - * @return string |
|
| 68 | - */ |
|
| 69 | - public function get_admin_edit_link() |
|
| 70 | - { |
|
| 71 | - return esc_url( |
|
| 72 | - add_query_arg( |
|
| 73 | - 'wp_http_referer', |
|
| 74 | - urlencode( |
|
| 75 | - wp_unslash( |
|
| 76 | - $_SERVER['REQUEST_URI'] |
|
| 77 | - ) |
|
| 78 | - ), |
|
| 79 | - get_edit_user_link($this->ID()) |
|
| 80 | - ) |
|
| 81 | - ); |
|
| 82 | - } |
|
| 64 | + /** |
|
| 65 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 66 | + * |
|
| 67 | + * @return string |
|
| 68 | + */ |
|
| 69 | + public function get_admin_edit_link() |
|
| 70 | + { |
|
| 71 | + return esc_url( |
|
| 72 | + add_query_arg( |
|
| 73 | + 'wp_http_referer', |
|
| 74 | + urlencode( |
|
| 75 | + wp_unslash( |
|
| 76 | + $_SERVER['REQUEST_URI'] |
|
| 77 | + ) |
|
| 78 | + ), |
|
| 79 | + get_edit_user_link($this->ID()) |
|
| 80 | + ) |
|
| 81 | + ); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Returns the link to a settings page for the object. |
|
| 86 | - * |
|
| 87 | - * @return string |
|
| 88 | - */ |
|
| 89 | - public function get_admin_settings_link() |
|
| 90 | - { |
|
| 91 | - return $this->get_admin_edit_link(); |
|
| 92 | - } |
|
| 84 | + /** |
|
| 85 | + * Returns the link to a settings page for the object. |
|
| 86 | + * |
|
| 87 | + * @return string |
|
| 88 | + */ |
|
| 89 | + public function get_admin_settings_link() |
|
| 90 | + { |
|
| 91 | + return $this->get_admin_edit_link(); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 96 | - * |
|
| 97 | - * @return string |
|
| 98 | - */ |
|
| 99 | - public function get_admin_overview_link() |
|
| 100 | - { |
|
| 101 | - return admin_url('users.php'); |
|
| 102 | - } |
|
| 94 | + /** |
|
| 95 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 96 | + * |
|
| 97 | + * @return string |
|
| 98 | + */ |
|
| 99 | + public function get_admin_overview_link() |
|
| 100 | + { |
|
| 101 | + return admin_url('users.php'); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | 104 | |
| 105 | 105 | } |
@@ -1,4 +1,4 @@ discard block |
||
| 1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 2 | 2 | exit('No direct script access allowed'); |
| 3 | 3 | } |
| 4 | 4 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | public function wp_user_obj() |
| 47 | 47 | { |
| 48 | - if (! $this->_wp_user_obj) { |
|
| 48 | + if ( ! $this->_wp_user_obj) { |
|
| 49 | 49 | $this->_wp_user_obj = get_user_by('ID', $this->ID()); |
| 50 | 50 | } |
| 51 | 51 | return $this->_wp_user_obj; |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | { |
| 68 | 68 | if ($this->country_currency_data === null) { |
| 69 | 69 | $country_currency_data = json_decode( |
| 70 | - EEH_File::get_file_contents(__DIR__ . DS . 'country-currencies.json'), |
|
| 70 | + EEH_File::get_file_contents(__DIR__.DS.'country-currencies.json'), |
|
| 71 | 71 | true |
| 72 | 72 | ); |
| 73 | 73 | $this->parseCountryCurrencyData($country_currency_data); |
@@ -83,8 +83,8 @@ discard block |
||
| 83 | 83 | private function parseCountryCurrencyData($country_currency_data) |
| 84 | 84 | { |
| 85 | 85 | foreach ($country_currency_data as $country_currency) { |
| 86 | - $this->country_currencies_by_iso_code[ $country_currency['CountryISO'] ] = $country_currency; |
|
| 87 | - $this->country_currencies_by_currency[ $country_currency['CurrencyCode'] ] = $country_currency; |
|
| 86 | + $this->country_currencies_by_iso_code[$country_currency['CountryISO']] = $country_currency; |
|
| 87 | + $this->country_currencies_by_currency[$country_currency['CurrencyCode']] = $country_currency; |
|
| 88 | 88 | } |
| 89 | 89 | $this->country_currency_data = $country_currency_data; |
| 90 | 90 | } |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | { |
| 129 | 129 | $this->getCountryCurrencyData(); |
| 130 | 130 | $CNT_ISO = $CNT_ISO !== null ? $CNT_ISO : $this->site_country_iso; |
| 131 | - if(! isset($this->country_currencies_by_iso_code[ $CNT_ISO ])) { |
|
| 131 | + if ( ! isset($this->country_currencies_by_iso_code[$CNT_ISO])) { |
|
| 132 | 132 | throw new InvalidArgumentException( |
| 133 | 133 | sprintf( |
| 134 | 134 | esc_html__( |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | ); |
| 141 | 141 | } |
| 142 | 142 | return $this->createCurrencyFromCountryCurrency( |
| 143 | - $this->country_currencies_by_iso_code[ $CNT_ISO ] |
|
| 143 | + $this->country_currencies_by_iso_code[$CNT_ISO] |
|
| 144 | 144 | ); |
| 145 | 145 | } |
| 146 | 146 | |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | public function createFromCode($code) |
| 163 | 163 | { |
| 164 | 164 | $this->getCountryCurrencyData(); |
| 165 | - if (! isset($this->country_currencies_by_currency[ $code ])) { |
|
| 165 | + if ( ! isset($this->country_currencies_by_currency[$code])) { |
|
| 166 | 166 | throw new InvalidArgumentException( |
| 167 | 167 | sprintf( |
| 168 | 168 | esc_html__( |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | ); |
| 175 | 175 | } |
| 176 | 176 | return $this->createCurrencyFromCountryCurrency( |
| 177 | - $this->country_currencies_by_currency[ $code ] |
|
| 177 | + $this->country_currencies_by_currency[$code] |
|
| 178 | 178 | ); |
| 179 | 179 | } |
| 180 | 180 | } |
@@ -24,147 +24,147 @@ |
||
| 24 | 24 | class CurrencyFactory |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var array[] $country_currency_data |
|
| 29 | - */ |
|
| 30 | - private $country_currency_data; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @var array[] $country_currencies_by_iso_code |
|
| 34 | - */ |
|
| 35 | - private $country_currencies_by_iso_code; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var array[] $country_currencies_by_currency |
|
| 39 | - */ |
|
| 40 | - private $country_currencies_by_currency; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var string $site_country_iso |
|
| 44 | - */ |
|
| 45 | - private $site_country_iso; |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * CurrencyFactory constructor. |
|
| 50 | - * |
|
| 51 | - * @param EE_Organization_Config $organization_config |
|
| 52 | - */ |
|
| 53 | - public function __construct(EE_Organization_Config $organization_config) { |
|
| 54 | - $this->site_country_iso = $organization_config->CNT_ISO; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @return array[] |
|
| 60 | - * @throws EE_Error |
|
| 61 | - */ |
|
| 62 | - private function getCountryCurrencyData() |
|
| 63 | - { |
|
| 64 | - if ($this->country_currency_data === null) { |
|
| 65 | - $country_currency_data = json_decode( |
|
| 66 | - EEH_File::get_file_contents(__DIR__ . DS . 'country-currencies.json'), |
|
| 67 | - true |
|
| 68 | - ); |
|
| 69 | - $this->parseCountryCurrencyData($country_currency_data); |
|
| 70 | - } |
|
| 71 | - return $this->country_currency_data; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @param array[] $country_currency_data |
|
| 77 | - */ |
|
| 78 | - private function parseCountryCurrencyData($country_currency_data) |
|
| 79 | - { |
|
| 80 | - foreach ($country_currency_data as $country_currency) { |
|
| 81 | - $this->country_currencies_by_iso_code[ $country_currency['CountryISO'] ] = $country_currency; |
|
| 82 | - $this->country_currencies_by_currency[ $country_currency['CurrencyCode'] ] = $country_currency; |
|
| 83 | - } |
|
| 84 | - $this->country_currency_data = $country_currency_data; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @param array $country_currency |
|
| 90 | - * @return Currency |
|
| 91 | - */ |
|
| 92 | - private function createCurrencyFromCountryCurrency(array $country_currency) |
|
| 93 | - { |
|
| 94 | - return new Currency( |
|
| 95 | - $country_currency['CurrencyCode'], |
|
| 96 | - new Label( |
|
| 97 | - $country_currency['CurrencyNameSingle'], |
|
| 98 | - $country_currency['CurrencyNamePlural'] |
|
| 99 | - ), |
|
| 100 | - $country_currency['CurrencySign'], |
|
| 101 | - $country_currency['CurrencySignB4'], |
|
| 102 | - $country_currency['CurrencyDecimalPlaces'], |
|
| 103 | - $country_currency['CurrencyDecimalMark'], |
|
| 104 | - $country_currency['CurrencyThousands'], |
|
| 105 | - $country_currency['CurrencySubunits'] |
|
| 106 | - ); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * returns a Currency object for the supplied country code |
|
| 113 | - * |
|
| 114 | - * @param string $CNT_ISO |
|
| 115 | - * @return Currency |
|
| 116 | - * @throws EE_Error |
|
| 117 | - * @throws InvalidArgumentException |
|
| 118 | - */ |
|
| 119 | - public function createFromCountryCode($CNT_ISO = null) |
|
| 120 | - { |
|
| 121 | - $this->getCountryCurrencyData(); |
|
| 122 | - $CNT_ISO = $CNT_ISO !== null ? $CNT_ISO : $this->site_country_iso; |
|
| 123 | - if(! isset($this->country_currencies_by_iso_code[ $CNT_ISO ])) { |
|
| 124 | - throw new InvalidArgumentException( |
|
| 125 | - sprintf( |
|
| 126 | - esc_html__( |
|
| 127 | - 'Valid country currency data could not be found for the "%1$s" country code;', |
|
| 128 | - 'event_espresso' |
|
| 129 | - ), |
|
| 130 | - $CNT_ISO |
|
| 131 | - ) |
|
| 132 | - ); |
|
| 133 | - } |
|
| 134 | - return $this->createCurrencyFromCountryCurrency( |
|
| 135 | - $this->country_currencies_by_iso_code[ $CNT_ISO ] |
|
| 136 | - ); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * returns a Currency object for the supplied currency code |
|
| 143 | - * PLZ NOTE: variations may exist between how different countries display the same currency, |
|
| 144 | - * so it may be necessary to use CreateCurrency::fromCountryCode() to achieve the desired results |
|
| 145 | - * |
|
| 146 | - * @param string $code |
|
| 147 | - * @return Currency |
|
| 148 | - * @throws InvalidArgumentException |
|
| 149 | - * @throws EE_Error |
|
| 150 | - */ |
|
| 151 | - public function createFromCode($code) |
|
| 152 | - { |
|
| 153 | - $this->getCountryCurrencyData(); |
|
| 154 | - if (! isset($this->country_currencies_by_currency[ $code ])) { |
|
| 155 | - throw new InvalidArgumentException( |
|
| 156 | - sprintf( |
|
| 157 | - esc_html__( |
|
| 158 | - 'A valid currency could not be found for the "%1$s" currency code;', |
|
| 159 | - 'event_espresso' |
|
| 160 | - ), |
|
| 161 | - $code |
|
| 162 | - ) |
|
| 163 | - ); |
|
| 164 | - } |
|
| 165 | - return $this->createCurrencyFromCountryCurrency( |
|
| 166 | - $this->country_currencies_by_currency[ $code ] |
|
| 167 | - ); |
|
| 168 | - } |
|
| 27 | + /** |
|
| 28 | + * @var array[] $country_currency_data |
|
| 29 | + */ |
|
| 30 | + private $country_currency_data; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @var array[] $country_currencies_by_iso_code |
|
| 34 | + */ |
|
| 35 | + private $country_currencies_by_iso_code; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var array[] $country_currencies_by_currency |
|
| 39 | + */ |
|
| 40 | + private $country_currencies_by_currency; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var string $site_country_iso |
|
| 44 | + */ |
|
| 45 | + private $site_country_iso; |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * CurrencyFactory constructor. |
|
| 50 | + * |
|
| 51 | + * @param EE_Organization_Config $organization_config |
|
| 52 | + */ |
|
| 53 | + public function __construct(EE_Organization_Config $organization_config) { |
|
| 54 | + $this->site_country_iso = $organization_config->CNT_ISO; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @return array[] |
|
| 60 | + * @throws EE_Error |
|
| 61 | + */ |
|
| 62 | + private function getCountryCurrencyData() |
|
| 63 | + { |
|
| 64 | + if ($this->country_currency_data === null) { |
|
| 65 | + $country_currency_data = json_decode( |
|
| 66 | + EEH_File::get_file_contents(__DIR__ . DS . 'country-currencies.json'), |
|
| 67 | + true |
|
| 68 | + ); |
|
| 69 | + $this->parseCountryCurrencyData($country_currency_data); |
|
| 70 | + } |
|
| 71 | + return $this->country_currency_data; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @param array[] $country_currency_data |
|
| 77 | + */ |
|
| 78 | + private function parseCountryCurrencyData($country_currency_data) |
|
| 79 | + { |
|
| 80 | + foreach ($country_currency_data as $country_currency) { |
|
| 81 | + $this->country_currencies_by_iso_code[ $country_currency['CountryISO'] ] = $country_currency; |
|
| 82 | + $this->country_currencies_by_currency[ $country_currency['CurrencyCode'] ] = $country_currency; |
|
| 83 | + } |
|
| 84 | + $this->country_currency_data = $country_currency_data; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @param array $country_currency |
|
| 90 | + * @return Currency |
|
| 91 | + */ |
|
| 92 | + private function createCurrencyFromCountryCurrency(array $country_currency) |
|
| 93 | + { |
|
| 94 | + return new Currency( |
|
| 95 | + $country_currency['CurrencyCode'], |
|
| 96 | + new Label( |
|
| 97 | + $country_currency['CurrencyNameSingle'], |
|
| 98 | + $country_currency['CurrencyNamePlural'] |
|
| 99 | + ), |
|
| 100 | + $country_currency['CurrencySign'], |
|
| 101 | + $country_currency['CurrencySignB4'], |
|
| 102 | + $country_currency['CurrencyDecimalPlaces'], |
|
| 103 | + $country_currency['CurrencyDecimalMark'], |
|
| 104 | + $country_currency['CurrencyThousands'], |
|
| 105 | + $country_currency['CurrencySubunits'] |
|
| 106 | + ); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * returns a Currency object for the supplied country code |
|
| 113 | + * |
|
| 114 | + * @param string $CNT_ISO |
|
| 115 | + * @return Currency |
|
| 116 | + * @throws EE_Error |
|
| 117 | + * @throws InvalidArgumentException |
|
| 118 | + */ |
|
| 119 | + public function createFromCountryCode($CNT_ISO = null) |
|
| 120 | + { |
|
| 121 | + $this->getCountryCurrencyData(); |
|
| 122 | + $CNT_ISO = $CNT_ISO !== null ? $CNT_ISO : $this->site_country_iso; |
|
| 123 | + if(! isset($this->country_currencies_by_iso_code[ $CNT_ISO ])) { |
|
| 124 | + throw new InvalidArgumentException( |
|
| 125 | + sprintf( |
|
| 126 | + esc_html__( |
|
| 127 | + 'Valid country currency data could not be found for the "%1$s" country code;', |
|
| 128 | + 'event_espresso' |
|
| 129 | + ), |
|
| 130 | + $CNT_ISO |
|
| 131 | + ) |
|
| 132 | + ); |
|
| 133 | + } |
|
| 134 | + return $this->createCurrencyFromCountryCurrency( |
|
| 135 | + $this->country_currencies_by_iso_code[ $CNT_ISO ] |
|
| 136 | + ); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * returns a Currency object for the supplied currency code |
|
| 143 | + * PLZ NOTE: variations may exist between how different countries display the same currency, |
|
| 144 | + * so it may be necessary to use CreateCurrency::fromCountryCode() to achieve the desired results |
|
| 145 | + * |
|
| 146 | + * @param string $code |
|
| 147 | + * @return Currency |
|
| 148 | + * @throws InvalidArgumentException |
|
| 149 | + * @throws EE_Error |
|
| 150 | + */ |
|
| 151 | + public function createFromCode($code) |
|
| 152 | + { |
|
| 153 | + $this->getCountryCurrencyData(); |
|
| 154 | + if (! isset($this->country_currencies_by_currency[ $code ])) { |
|
| 155 | + throw new InvalidArgumentException( |
|
| 156 | + sprintf( |
|
| 157 | + esc_html__( |
|
| 158 | + 'A valid currency could not be found for the "%1$s" currency code;', |
|
| 159 | + 'event_espresso' |
|
| 160 | + ), |
|
| 161 | + $code |
|
| 162 | + ) |
|
| 163 | + ); |
|
| 164 | + } |
|
| 165 | + return $this->createCurrencyFromCountryCurrency( |
|
| 166 | + $this->country_currencies_by_currency[ $code ] |
|
| 167 | + ); |
|
| 168 | + } |
|
| 169 | 169 | } |
| 170 | 170 | // Location: CreateCurrency.php |
@@ -30,7 +30,7 @@ |
||
| 30 | 30 | public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
| 31 | 31 | { |
| 32 | 32 | if ($schema === 'form_input') { |
| 33 | - $value_on_field_to_be_outputted = (string)htmlentities( |
|
| 33 | + $value_on_field_to_be_outputted = (string) htmlentities( |
|
| 34 | 34 | $value_on_field_to_be_outputted, |
| 35 | 35 | ENT_QUOTES, |
| 36 | 36 | 'UTF-8' |
@@ -7,49 +7,49 @@ |
||
| 7 | 7 | abstract class EE_Text_Field_Base extends EE_Model_Field_Base |
| 8 | 8 | { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * Gets the value in the format expected when being set. |
|
| 12 | - * For display on the front-end, usually you would use prepare_for_pretty_echoing() instead. |
|
| 13 | - * @param mixed $value_of_field_on_model_object |
|
| 14 | - * @return mixed|string |
|
| 15 | - */ |
|
| 16 | - public function prepare_for_get($value_of_field_on_model_object) |
|
| 17 | - { |
|
| 18 | - return $value_of_field_on_model_object; |
|
| 19 | - } |
|
| 10 | + /** |
|
| 11 | + * Gets the value in the format expected when being set. |
|
| 12 | + * For display on the front-end, usually you would use prepare_for_pretty_echoing() instead. |
|
| 13 | + * @param mixed $value_of_field_on_model_object |
|
| 14 | + * @return mixed|string |
|
| 15 | + */ |
|
| 16 | + public function prepare_for_get($value_of_field_on_model_object) |
|
| 17 | + { |
|
| 18 | + return $value_of_field_on_model_object; |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Accepts schema of 'form_input' which formats the string for echoing in form input's value. |
|
| 23 | - * |
|
| 24 | - * @param string $value_on_field_to_be_outputted |
|
| 25 | - * @param string $schema |
|
| 26 | - * @return string |
|
| 27 | - */ |
|
| 28 | - public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
| 29 | - { |
|
| 30 | - if ($schema === 'form_input') { |
|
| 31 | - $value_on_field_to_be_outputted = (string)htmlentities( |
|
| 32 | - $value_on_field_to_be_outputted, |
|
| 33 | - ENT_QUOTES, |
|
| 34 | - 'UTF-8' |
|
| 35 | - ); |
|
| 36 | - } |
|
| 37 | - return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted); |
|
| 38 | - } |
|
| 21 | + /** |
|
| 22 | + * Accepts schema of 'form_input' which formats the string for echoing in form input's value. |
|
| 23 | + * |
|
| 24 | + * @param string $value_on_field_to_be_outputted |
|
| 25 | + * @param string $schema |
|
| 26 | + * @return string |
|
| 27 | + */ |
|
| 28 | + public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
| 29 | + { |
|
| 30 | + if ($schema === 'form_input') { |
|
| 31 | + $value_on_field_to_be_outputted = (string)htmlentities( |
|
| 32 | + $value_on_field_to_be_outputted, |
|
| 33 | + ENT_QUOTES, |
|
| 34 | + 'UTF-8' |
|
| 35 | + ); |
|
| 36 | + } |
|
| 37 | + return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Data received from the user should be exactly as they hope to save it in the DB, with the exception that |
|
| 42 | - * quotes need to have slashes added to it. This method takes care of removing the slashes added by WP |
|
| 43 | - * in magic-quotes fashion. We used to call html_entity_decode on the value here, |
|
| 44 | - * because we called htmlentities when in EE_Text_Field_Base::prepare_for_pretty_echoing, but that's not necessary |
|
| 45 | - * because web browsers always decode HTML entities in element attributes, like a form element's value attribute. |
|
| 46 | - * So if we do it again here, we'll be removing HTML entities the user intended to have.) |
|
| 47 | - * |
|
| 48 | - * @param string $value_inputted_for_field_on_model_object |
|
| 49 | - * @return string |
|
| 50 | - */ |
|
| 51 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 52 | - { |
|
| 53 | - return stripslashes(parent::prepare_for_set($value_inputted_for_field_on_model_object)); |
|
| 54 | - } |
|
| 40 | + /** |
|
| 41 | + * Data received from the user should be exactly as they hope to save it in the DB, with the exception that |
|
| 42 | + * quotes need to have slashes added to it. This method takes care of removing the slashes added by WP |
|
| 43 | + * in magic-quotes fashion. We used to call html_entity_decode on the value here, |
|
| 44 | + * because we called htmlentities when in EE_Text_Field_Base::prepare_for_pretty_echoing, but that's not necessary |
|
| 45 | + * because web browsers always decode HTML entities in element attributes, like a form element's value attribute. |
|
| 46 | + * So if we do it again here, we'll be removing HTML entities the user intended to have.) |
|
| 47 | + * |
|
| 48 | + * @param string $value_inputted_for_field_on_model_object |
|
| 49 | + * @return string |
|
| 50 | + */ |
|
| 51 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
| 52 | + { |
|
| 53 | + return stripslashes(parent::prepare_for_set($value_inputted_for_field_on_model_object)); |
|
| 54 | + } |
|
| 55 | 55 | } |
| 56 | 56 | \ No newline at end of file |