���� JFIF    �� �        "" $(4,$&1'-=-157:::#+?D?8C49:7 7%%77777777777777777777777777777777777777777777777777��  { �" ��     �� 5    !1AQa"q�2��BR��#b�������  ��  ��   ? ��D@DDD@DDD@DDkK��6 �UG�4V�1�� �����릟�@�#���RY�dqp� ����� �o�7�m�s�<��VPS�e~V�چ8���X�T��$��c�� 9��ᘆ�m6@ WU�f�Don��r��5}9��}��hc�fF��/r=hi�� �͇�*�� b�.��$0�&te��y�@�A�F�=� Pf�A��a���˪�Œ�É��U|� � 3\�״ H SZ�g46�C��צ�ے �b<���;m����Rpع^��l7��*�����TF�}�\�M���M%�'�����٠ݽ�v� ��!-�����?�N!La��A+[`#���M����'�~oR�?��v^)��=��h����A��X�.���˃����^Ə��ܯsO"B�c>; �e�4��5�k��/CB��.  �J?��;�҈�������������������~�<�VZ�ꭼ2/)Í”jC���ע�V�G�!���!�F������\�� Kj�R�oc�h���:Þ I��1"2�q×°8��Р@ז���_C0�ր��A��lQ��@纼�!7��F�� �]�sZ B�62r�v�z~�K�7�c��5�.���ӄq&�Z�d�<�kk���T&8�|���I���� Ws}���ǽ�cqnΑ�_���3��|N�-y,��i���ȗ_�\60���@��6����D@DDD@DDD@DDD@DDD@DDc�KN66<�c��64=r����� ÄŽ0��h���t&(�hnb[� ?��^��\��â|�,�/h�\��R��5�? �0�!צ܉-����G����٬��Q�zA���1�����V��� �:R���`�$��ik��H����D4�����#dk����� h�}����7���w%�������*o8wG�LycuT�.���ܯ7��I��u^���)��/c�,s�Nq�ۺ�;�ך�YH2���.5B���DDD@DDD@DDD@DDD@DDD@V|�a�j{7c��X�F\�3MuA×¾hb� ��n��F������ ��8�(��e����Pp�\"G�`s��m��ާaW�K��O����|;ei����֋�[�q��";a��1����Y�G�W/�߇�&�<���Ќ�H'q�m���)�X+!���=�m�ۚ丷~6a^X�)���,�>#&6G���Y��{����"" """ """ """ """ ""��at\/�a�8 �yp%�lhl�n����)���i�t��B�������������?��modskinlienminh.com - WSOX ENC class.rest-api.php000064400000002725146731356360010131 0ustar00 'GET', 'callback' => array( $this, 'get_all_posts' ), 'permission_callback' => function () { return current_user_can( 'edit_posts' ); }, ) ); } /** * Get all posts and pages */ public function get_all_posts() { $all_posts = get_posts( array( 'post_type' => $this->get_post_type(), 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'ASC', 'posts_per_page' => -1, // all posts ) ); if ( $all_posts ) { $source = array(); foreach ( $all_posts as $k => $post ) { $source[ $k ]['id'] = $post->ID; $source[ $k ]['text'] = $post->ID . ' - ' . $post->post_title; } } return $source; } /** * Get posts type. */ public function get_post_type() { $post_type = $this->post_type; return apply_filters( SCF_Config::PREFIX . 'rest_api_post_type', $post_type ); } } fields/class.field-related-terms.php000064400000021756146731356360013511 0ustar00 'taxonomy', 'display-name' => __( 'Related Terms', 'smart-custom-fields' ), 'optgroup' => 'other-fields', 'allow-multiple-data' => true, ); } /** * Set the non required items. * * @return array */ protected function options() { return array( 'taxonomy' => '', 'limit' => 0, 'instruction' => '', 'notes' => '', ); } /** * Loading resources. */ public function admin_enqueue_scripts() { wp_enqueue_script( SCF_Config::PREFIX . 'editor-relation-common', SMART_CUSTOM_FIELDS_URL . '/js/editor-relation-common.js', array( 'jquery' ), filemtime( SMART_CUSTOM_FIELDS_PATH . '/js/editor-relation-common.js' ), true ); wp_enqueue_script( SCF_Config::PREFIX . 'editor-relation-taxonomies', SMART_CUSTOM_FIELDS_URL . '/js/editor-relation-taxonomies.js', array( 'jquery' ), filemtime( SMART_CUSTOM_FIELDS_PATH . '/js/editor-relation-taxonomies.js' ), true ); wp_localize_script( SCF_Config::PREFIX . 'editor-relation-taxonomies', 'smart_cf_relation_taxonomies', array( 'endpoint' => admin_url( 'admin-ajax.php' ), 'action' => SCF_Config::PREFIX . 'relational-terms-search', 'nonce' => wp_create_nonce( SCF_Config::NAME . '-relation-taxonomies' ), ) ); } /** * Process that loading post when clicking post load button. */ public function relational_terms_search() { check_ajax_referer( SCF_Config::NAME . '-relation-taxonomies', 'nonce' ); $_terms = array(); $taxonomies = filter_input( INPUT_POST, 'taxonomies' ); if ( $taxonomies ) { $taxonomies = explode( ',', $taxonomies ); $retrievable_taxonomies = array(); foreach ( $taxonomies as $_taxonomy ) { $tax = get_taxonomy( $_taxonomy ); if ( current_user_can( $tax->cap->manage_terms ) ) { $retrievable_taxonomies[] = $_taxonomy; } } if ( $retrievable_taxonomies ) { $args = array( 'taxonomy' => $retrievable_taxonomies, 'order' => 'ASC', 'orderby' => 'ID', 'number' => '', 'hide_empty' => false, 'hierarchical' => false, ); $click_count = filter_input( INPUT_POST, 'click_count' ); if ( $click_count ) { $number = get_option( 'posts_per_page' ); $offset = $click_count * $number; $args = array_merge( $args, array( 'offset' => $offset, 'number' => $number, ) ); } $search = filter_input( INPUT_POST, 'search' ); if ( $search ) { $args = array_merge( $args, array( 'search' => $search, ) ); } $_terms = get_terms( $args ); } } header( 'Content-Type: application/json; charset=utf-8' ); echo wp_json_encode( $_terms ); die(); } /** * Getting the field. * * @param int $index Field index. * @param string $value The value. * @return string */ public function get_field( $index, $value ) { $name = $this->get_field_name_in_editor( $index ); $disabled = $this->get_disable_attribute( $index ); $taxonomies = $this->get( 'taxonomy' ); $limit = $this->get( 'limit' ); $choices_terms = array(); $number = get_option( 'posts_per_page' ); if ( $taxonomies ) { $retrievable_taxonomies = array(); foreach ( $taxonomies as $_taxonomy ) { $tax = get_taxonomy( $_taxonomy ); if ( current_user_can( $tax->cap->manage_terms ) ) { $retrievable_taxonomies[] = $_taxonomy; } } if ( $retrievable_taxonomies ) { if ( ! preg_match( '/^\d+$/', $limit ) ) { $limit = ''; } // choicse $choices_terms = get_terms( array( 'taxonomy' => $taxonomies, 'order' => 'ASC', 'orderby' => 'ID', 'hide_empty' => false, 'hierarchical' => false, 'number' => $number, ) ); } } $choices_li = array(); foreach ( $choices_terms as $_term ) { $term_name = $_term->name; if ( empty( $term_name ) ) { $term_name = ' '; } $choices_li[] = sprintf( '
  • %s
  • ', $_term->term_id, $term_name ); } // selected $selected_terms = array(); if ( ! empty( $value ) && is_array( $value ) ) { foreach ( $value as $term_id ) { $term_name = get_term( $term_id )->name; if ( empty( $term_name ) ) { $term_name = ' '; } $selected_terms[ $term_id ] = $term_name; } } $selected_li = array(); $hidden = array(); foreach ( $selected_terms as $term_id => $term_name ) { $selected_li[] = sprintf( '
  • %s-
  • ', $term_id, esc_attr( SCF_Config::PREFIX . 'icon-handle dashicons dashicons-menu' ), $term_name ); $hidden[] = sprintf( '', esc_attr( $name . '[]' ), $term_id, disabled( true, $disabled, false ) ); } $hide_class = ''; if ( count( $choices_li ) < $number ) { $hide_class = 'hide'; } return sprintf( '
      %s

    %s

    %s
    ', SCF_Config::PREFIX . 'relation-left', implode( ',', $taxonomies ), $limit, SCF_Config::PREFIX . 'search', esc_attr__( 'Search...', 'smart-custom-fields' ), SCF_Config::PREFIX . 'relation-children-select', implode( '', $choices_li ), $hide_class, esc_html__( 'Load more', 'smart-custom-fields' ), esc_attr( $name ), disabled( true, $disabled, false ), implode( '', $hidden ), SCF_Config::PREFIX . 'relation-right', implode( '', $selected_li ) ); } /** * Displaying the option fields in custom field settings page. * * @param int $group_key Group key. * @param int $field_key Field key. */ public function display_field_options( $group_key, $field_key ) { $this->display_label_option( $group_key, $field_key ); $this->display_name_option( $group_key, $field_key ); ?> true, ), 'objects' ); ?> $taxonomy_object ) : ?> get( 'taxonomy' ); ?> checked="checked" />labels->singular_name ); ?> get_attribute( 'type' ) ) { $validated_value = array(); foreach ( $value as $term ) { $validated_value[] = $term; } $value = $validated_value; } return $value; } } fields/class.field-text.php000064400000004571146731356360011721 0ustar00 'text', 'display-name' => __( 'Text', 'smart-custom-fields' ), 'optgroup' => 'basic-fields', ); } /** * Set the non required items. * * @return array */ protected function options() { return array( 'default' => '', 'instruction' => '', 'notes' => '', ); } /** * Getting the field. * * @param int $index Field index. * @param string $value The value. * @return string */ public function get_field( $index, $value ) { $name = $this->get_field_name_in_editor( $index ); $disabled = $this->get_disable_attribute( $index ); return sprintf( '', esc_attr( $name ), esc_attr( $value ), disabled( true, $disabled, false ) ); } /** * Displaying the option fields in custom field settings page. * * @param int $group_key Group key. * @param int $field_key Field key. */ public function display_field_options( $group_key, $field_key ) { $this->display_label_option( $group_key, $field_key ); $this->display_name_option( $group_key, $field_key ); ?> 'relation', 'display-name' => __( 'Related Posts', 'smart-custom-fields' ), 'optgroup' => 'other-fields', 'allow-multiple-data' => true, ); } /** * Set the non required items. * * @return array */ protected function options() { return array( 'post-type' => '', 'limit' => 0, 'instruction' => '', 'notes' => '', ); } /** * Loading resources. */ public function admin_enqueue_scripts() { wp_enqueue_script( SCF_Config::PREFIX . 'editor-relation-common', SMART_CUSTOM_FIELDS_URL . '/js/editor-relation-common.js', array( 'jquery' ), filemtime( SMART_CUSTOM_FIELDS_PATH . '/js/editor-relation-common.js' ), true ); wp_enqueue_script( SCF_Config::PREFIX . 'editor-relation-post-types', SMART_CUSTOM_FIELDS_URL . '/js/editor-relation-post-types.js', array( 'jquery' ), filemtime( SMART_CUSTOM_FIELDS_PATH . '/js/editor-relation-post-types.js' ), true ); wp_localize_script( SCF_Config::PREFIX . 'editor-relation-post-types', 'smart_cf_relation_post_types', array( 'endpoint' => admin_url( 'admin-ajax.php' ), 'action' => SCF_Config::PREFIX . 'relational-posts-search', 'nonce' => wp_create_nonce( SCF_Config::NAME . '-relation-post-types' ), ) ); } /** * Process that loading post when clicking post load button. */ public function relational_posts_search() { check_ajax_referer( SCF_Config::NAME . '-relation-post-types', 'nonce' ); $_posts = array(); $post_types = filter_input( INPUT_POST, 'post_types' ); if ( $post_types ) { $post_type = explode( ',', $post_types ); $retrievable_post_types = array(); foreach ( $post_type as $_post_type ) { $post_type_object = get_post_type_object( $_post_type ); if ( current_user_can( $post_type_object->cap->edit_posts ) ) { $retrievable_post_types[] = $_post_type; } } if ( $retrievable_post_types ) { $args = array( 'post_type' => $retrievable_post_types, 'order' => 'ASC', 'orderby' => 'ID', 'posts_per_page' => -1, 'post_status' => 'any', ); $click_count = filter_input( INPUT_POST, 'click_count' ); if ( $click_count ) { $posts_per_page = get_option( 'posts_per_page' ); $offset = $click_count * $posts_per_page; $args = array_merge( $args, array( 'offset' => $offset, 'posts_per_page' => $posts_per_page, ) ); } $s = filter_input( INPUT_POST, 's' ); if ( $s ) { $args = array_merge( $args, array( 's' => $s, ) ); } $field_name = sanitize_text_field( filter_input( INPUT_POST, 'field_name' ) ); /** * This filter will be always applied when it queries posts in related posts field. */ $args = apply_filters( SCF_Config::PREFIX . 'custom_related_posts_args', $args, $field_name, $post_type ); /** * This filter will only be applied when getting posts via ajax call, therefore it won't be applied for the first load. */ $args = apply_filters( SCF_Config::PREFIX . 'custom_related_posts_args_ajax_call', $args, $field_name, $post_type ); $_posts = get_posts( $args ); } } header( 'Content-Type: application/json; charset=utf-8' ); echo wp_json_encode( $_posts ); die(); } /** * Getting the field. * * @param int $index Field index. * @param array $value The value. * @return string */ public function get_field( $index, $value ) { $name = $this->get_field_name_in_editor( $index ); $disabled = $this->get_disable_attribute( $index ); $post_type = $this->get( 'post-type' ); $limit = $this->get( 'limit' ); $choices_posts = array(); $posts_per_page = get_option( 'posts_per_page' ); if ( $post_type ) { $retrievable_post_types = array(); foreach ( $post_type as $_post_type ) { $post_type_object = get_post_type_object( $_post_type ); if ( current_user_can( $post_type_object->cap->edit_posts ) ) { $retrievable_post_types[] = $_post_type; } } if ( $retrievable_post_types ) { if ( ! preg_match( '/^\d+$/', $limit ) ) { $limit = ''; } $args = array( 'post_type' => $retrievable_post_types, 'order' => 'ASC', 'orderby' => 'ID', 'posts_per_page' => $posts_per_page, 'post_status' => 'any', ); /** * This filter will be always applied when it queries posts in related posts field. */ $args = apply_filters( SCF_Config::PREFIX . 'custom_related_posts_args', $args, $name, $post_type ); /** * This filter will only be applied in the first load, therefore it won't be applied when getting posts via ajax call. */ $args = apply_filters( SCF_Config::PREFIX . 'custom_related_posts_args_first_load', $args, $name, $post_type ); // Get posts to show in the first load. $choices_posts = get_posts( $args ); } } $choices_li = array(); foreach ( $choices_posts as $_post ) { $post_title = get_the_title( $_post->ID ); if ( empty( $post_title ) ) { $post_title = ' '; } $choices_li[] = sprintf( '
  • %s
  • ', $_post->ID, $_post->post_status, $post_title ); } // selected $selected_posts = array(); if ( ! empty( $value ) && is_array( $value ) ) { foreach ( $value as $post_id ) { $post_title = get_the_title( $post_id ); if ( empty( $post_title ) ) { $post_title = ' '; } $selected_posts[ $post_id ] = $post_title; } } $selected_li = array(); $hidden = array(); foreach ( $selected_posts as $post_id => $post_title ) { $selected_li[] = sprintf( '
  • %s-
  • ', $post_id, get_post_status( $post_id ), esc_attr( SCF_Config::PREFIX . 'icon-handle dashicons dashicons-menu' ), $post_title ); $hidden[] = sprintf( '', esc_attr( $name . '[]' ), $post_id, disabled( true, $disabled, false ) ); } $hide_class = ''; if ( count( $choices_li ) < $posts_per_page ) { $hide_class = 'hide'; } return sprintf( '
      %s

    %s

    %s
    ', SCF_Config::PREFIX . 'relation-left', implode( ',', $post_type ), $limit, SCF_Config::PREFIX . 'search', esc_attr__( 'Search...', 'smart-custom-fields' ), SCF_Config::PREFIX . 'relation-children-select', implode( '', $choices_li ), $hide_class, esc_html__( 'Load more', 'smart-custom-fields' ), esc_attr( $name ), disabled( true, $disabled, false ), implode( '', $hidden ), SCF_Config::PREFIX . 'relation-right', implode( '', $selected_li ) ); } /** * Displaying the option fields in custom field settings page. * * @param int $group_key Group key. * @param int $field_key Field key. */ public function display_field_options( $group_key, $field_key ) { $this->display_label_option( $group_key, $field_key ); $this->display_name_option( $group_key, $field_key ); ?> true, ), 'objects' ); unset( $post_types['attachment'] ); unset( $post_types['wp_block'] ); unset( $post_types[ SCF_Config::NAME ] ); ?> $post_type_object ) : ?> get( 'post-type' ); ?> checked="checked" />labels->singular_name ); ?> get_attribute( 'type' ) ) { $validated_value = array(); foreach ( $value as $post_id ) { $validated_value[] = $post_id; } $value = $validated_value; } return $value; } } fields/class.field-textarea.php000064400000005440146731356360012546 0ustar00 'textarea', 'display-name' => __( 'Textarea', 'smart-custom-fields' ), 'optgroup' => 'basic-fields', ); } /** * Set the non required items. * * @return array */ protected function options() { return array( 'rows' => 5, 'default' => '', 'instruction' => '', 'notes' => '', ); } /** * Getting the field. * * @param int $index Field index. * @param string $value The value. * @return string */ public function get_field( $index, $value ) { $name = $this->get_field_name_in_editor( $index ); $disabled = $this->get_disable_attribute( $index ); $rows = $this->get( 'rows' ); return sprintf( '', esc_attr( $name ), esc_attr( $rows ), disabled( true, $disabled, false ), esc_textarea( $value ) ); } /** * Displaying the option fields in custom field settings page. * * @param int $group_key Group key. * @param int $field_key Field key. */ public function display_field_options( $group_key, $field_key ) { $this->display_label_option( $group_key, $field_key ); $this->display_name_option( $group_key, $field_key ); ?> */ /** * Smart_Custom_Fields_Field_Datetime_Picker class. * * @since 4.x */ class Smart_Custom_Fields_Field_Datetime_Picker extends Smart_Custom_Fields_Field_Base { /** * Set the required items. * * @return array */ protected function init() { add_action( SCF_Config::PREFIX . 'before-editor-enqueue-scripts', array( $this, 'editor_enqueue_scripts' ) ); add_action( SCF_Config::PREFIX . 'before-settings-enqueue-scripts', array( $this, 'settings_enqueue_scripts' ) ); return array( 'type' => 'datetime_picker', 'display-name' => __( 'Datetime picker', 'smart-custom-fields' ), 'optgroup' => 'other-fields', ); } /** * Set the non required items. * * @return array */ protected function options() { return array( 'date_format' => '', 'max_date' => '', 'min_date' => '', 'time_24hr' => '', 'default' => '', 'instruction' => '', 'notes' => '', ); } /** * Loading resources for editor. */ public function editor_enqueue_scripts() { wp_enqueue_style( 'flatpickr-style', '//cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css', array(), 1 ); wp_enqueue_script( 'flatpickr-script', '//cdn.jsdelivr.net/npm/flatpickr', array(), 1, true ); wp_enqueue_script( SCF_Config::PREFIX . 'flatpickr-script', SMART_CUSTOM_FIELDS_URL . '/js/settings-datetime-picker.js', array( 'flatpickr-script' ), filemtime( SMART_CUSTOM_FIELDS_PATH . '/js/settings-datetime-picker.js' ), true ); $locale = $this->get_locale_name(); if ( $locale ) { wp_enqueue_script( "flatpickr-lang-{$locale}", "//npmcdn.com/flatpickr/dist/l10n/{$locale}.js", array(), 1, true ); } } /** * Loading resources for editor for custom field settings page. */ public function settings_enqueue_scripts() { wp_enqueue_style( 'flatpickr-style', '//cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css', array(), 1 ); wp_enqueue_script( 'flatpickr-script', '//cdn.jsdelivr.net/npm/flatpickr', array(), 1, true ); wp_enqueue_script( SCF_Config::PREFIX . 'flatpickr-script', SMART_CUSTOM_FIELDS_URL . '/js/settings-datetime-picker.js', array( 'flatpickr-script' ), filemtime( SMART_CUSTOM_FIELDS_PATH . '/js/settings-datetime-picker.js' ), true ); $locale = $this->get_locale_name(); if ( $locale ) { wp_enqueue_script( "flatpickr-lang-{$locale}", "//npmcdn.com/flatpickr/dist/l10n/{$locale}.js", array(), 1, true ); } } /** * Get the field. * * @param int $index Field index. * @param string $value The value. * @return string */ public function get_field( $index, $value ) { $name = $this->get_field_name_in_editor( $index ); $disabled = $this->get_disable_attribute( $index ); $data_js = $this->get_data_js(); return ''; } /** * Displaying the option fields in custom field settings page. * * @param int $group_key Group key. * @param int $field_key Field key. */ public function display_field_options( $group_key, $field_key ) { $this->display_label_option( $group_key, $field_key ); $this->display_name_option( $group_key, $field_key ); ?>
    ', '' ); esc_html_e( 'This datetime picker currently does not include the timezone support, therefore you need to include some information on the instruction field below to enforce everyone to use the same timezone. The value returned by this field is always a plain text of date string.', 'smart-custom-fields' ); ?>
    ', '' ); ?>
    ', '' ); ?>
    get_locale_name() ) { $data['locale'] = $this->get_locale_name(); } if ( $this->get( 'date_format' ) ) { $data['dateFormat'] = $this->get( 'date_format' ); } if ( $this->get( 'max_date' ) ) { $data['maxDate'] = $this->get( 'max_date' ); } if ( $this->get( 'min_date' ) ) { $data['minDate'] = $this->get( 'min_date' ); } if ( $this->get( 'time_24hr' ) ) { $data['time_24hr'] = $this->get( 'time_24hr' ); } $data = apply_filters( SCF_Config::PREFIX . 'datetime_picker_data', $data ); return wp_json_encode( $data ); } /** * Return locale name for flatpickr. * * @return false|string $locale Locale. */ private function get_locale_name() { /** * The locale list is hardcoded here. Because of this, when flatpickr adds support for new language it's required to update the list. * * The list is from: https://github.com/flatpickr/flatpickr/blob/master/src/l10n/index.ts * Or at https://github.com/flatpickr/flatpickr/tree/master/src/l10n , * run the following script and copy the result: * const list = document.querySelectorAll('.files .content > span > a'); const items = []; for (const item of list) { items.push(item.innerHTML.split('.')[0]) }; console.log(items) */ $supported_locales = array( 'ar', 'at', 'be', 'bg', 'bn', 'cat', 'cs', 'cy', 'da', 'de', 'eo', 'es', 'et', 'fa', 'fi', 'fo', 'fr', 'gr', 'he', 'hi', 'hr', 'hu', 'id', 'it', 'ja', 'km', 'ko', 'kz', 'lt', 'lv', 'mk', 'mn', 'ms', 'my', 'nl', 'no', 'pa', 'pl', 'pt', 'ro', 'ru', 'si', 'sk', 'sl', 'sq', 'sr', 'sv', 'th', 'tr', 'uk', 'vn', 'zh', ); $wp_locale = get_locale(); if ( strpos( $wp_locale, '_' ) ) { $_user_lang = explode( $wp_locale, '_' ); $user_lang = $_user_lang[0]; } else { $user_lang = $wp_locale; } if ( in_array( $user_lang, $supported_locales, true ) ) { return $user_lang; } return false; } } fields/class.field-file.php000064400000007057146731356360011656 0ustar00 'file', 'display-name' => __( 'File', 'smart-custom-fields' ), 'optgroup' => 'content-fields', ); } /** * Set the non required items. * * @return array */ protected function options() { return array( 'instruction' => '', 'notes' => '', ); } /** * Getting the field. * * @param int $index Field index. * @param string $value The value. * @return string */ public function get_field( $index, $value ) { $name = $this->get_field_name_in_editor( $index ); $disabled = $this->get_disable_attribute( $index ); $btn_remove = sprintf( '%s', esc_html__( 'Delete', 'smart-custom-fields' ) ); $hide_class = 'hide'; $image = $btn_remove; if ( $value ) { // Usually, $value is attachment ID. // If a customized, for example, $value is not an ID, // Regarded the $value is file URL. if ( preg_match( '/^\d+$/', $value ) ) { $image_src = wp_get_attachment_image_src( $value, 'thumbnail', true ); $image_alt = get_the_title( $value ); if ( is_array( $image_src ) && isset( $image_src[0] ) ) { $image_src = $image_src[0]; } } else { $image_url = $value; $path = str_replace( home_url(), '', $value ); $image_path = ABSPATH . untrailingslashit( $path ); if ( file_exists( $image_path ) ) { $wp_check_filetype = wp_check_filetype( $image_path ); if ( ! empty( $wp_check_filetype['type'] ) ) { $image_src = $image_url; } } } if ( $image_src && ! is_array( $image_src ) ) { $filename = wp_basename( get_attached_file( $value ) ); $image = sprintf( '%s%s%s', wp_get_attachment_url( $value ), esc_url( $image_src ), $image_alt, esc_attr( $filename ), $btn_remove ); $hide_class = ''; } } return sprintf( '%s
    %s ', esc_html__( 'File Select', 'smart-custom-fields' ), esc_attr( SCF_Config::PREFIX . 'upload-file' ), esc_attr( $hide_class ), $image, esc_attr( $name ), esc_attr( $value ), disabled( true, $disabled, false ) ); } /** * Displaying the option fields in custom field settings page. * * @param int $group_key Group key. * @param int $field_key Field key. */ public function display_field_options( $group_key, $field_key ) { $this->display_label_option( $group_key, $field_key ); $this->display_name_option( $group_key, $field_key ); ?> 'boolean', 'display-name' => __( 'Boolean', 'smart-custom-fields' ), 'optgroup' => 'basic-fields', ); } /** * Set the non required items. * * @return array */ protected function options() { return array( 'default' => 0, 'instruction' => '', 'notes' => '', 'true_label' => __( 'Yes', 'smart-custom-fields' ), 'false_label' => __( 'No', 'smart-custom-fields' ), ); } /** * Getting the field. * * @param int $index Field index. * @param int $value The value. * @return string */ public function get_field( $index, $value ) { $name = $this->get_field_name_in_editor( $index ); $disabled = $this->get_disable_attribute( $index ); $value = ( true === $value || 1 === $value || '1' === $value ) ? 1 : 0; $true = sprintf( '', esc_attr( $name ), checked( 1, $value, false ), disabled( true, $disabled, false ), $this->get( 'true_label' ) ); $false = sprintf( '', esc_attr( $name ), checked( 0, $value, false ), disabled( true, $disabled, false ), $this->get( 'false_label' ) ); return $true . $false; } /** * Displaying the option fields in custom field settings page. * * @param int $group_key Group key. * @param int $field_key Field key. */ public function display_field_options( $group_key, $field_key ) { $this->display_label_option( $group_key, $field_key ); $this->display_name_option( $group_key, $field_key ); ?>
     
    get_attribute( 'type' ) ) { if ( is_array( $value ) ) { foreach ( $value as $key => $val ) { $value[ $key ] = ! ! $val; } } else { $value = ! ! $value; } } return $value; } } fields/class.field-radio.php000064400000010233146731356360012023 0ustar00 'radio', 'display-name' => __( 'Radio', 'smart-custom-fields' ), 'optgroup' => 'select-fields', ); } /** * Set the non required items. * * @return array */ protected function options() { return array( 'choices' => '', 'radio_direction' => 'horizontal', // or vertical 'default' => '', 'instruction' => '', 'notes' => '', ); } /** * Getting the field. * * @param int $index Field index. * @param string $value The value. * @return string */ public function get_field( $index, $value ) { $name = $this->get_field_name_in_editor( $index ); $disabled = $this->get_disable_attribute( $index ); $choices = SCF::choices_eol_to_array( $this->get( 'choices' ) ); $direction = $this->get( 'radio_direction' ); $form_field = sprintf( '', esc_attr( $name ), disabled( true, $disabled, false ) ); foreach ( $choices as $key => $choice ) { $choice = trim( $choice ); if ( ! SCF::is_assoc( $choices ) ) { $key = $choice; } $form_field .= sprintf( '', esc_attr( SCF_Config::PREFIX . 'item-' . $direction ), esc_attr( $name ), esc_attr( $key ), checked( $value, $key, false ), disabled( true, $disabled, false ), esc_html( $choice ) ); } return $form_field; } /** * Displaying the option fields in custom field settings page. * * @param int $group_key Group key. * @param int $field_key Field key. */ public function display_field_options( $group_key, $field_key ) { $this->display_label_option( $group_key, $field_key ); $this->display_name_option( $group_key, $field_key ); ?> value', 'smart-custom-fields' ); ?> __( 'horizontal', 'smart-custom-fields' ), 'vertical' => __( 'vertical', 'smart-custom-fields' ), ); foreach ( $directions as $key => $value ) { printf( '   ', esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'radio_direction' ) ), esc_attr( $key ), checked( $this->get( 'radio_direction' ), $key, false ), esc_html( $value ) ); } ?> 'check', 'display-name' => __( 'Check', 'smart-custom-fields' ), 'optgroup' => 'select-fields', 'allow-multiple-data' => true, ); } /** * Set the non required items. * * @return array */ protected function options() { return array( 'choices' => '', 'check_direction' => 'horizontal', // or vertical 'default' => '', 'instruction' => '', 'notes' => '', ); } /** * Getting the field. * * @param int $index Field index. * @param array $value The value. * @return string */ public function get_field( $index, $value ) { $name = $this->get_field_name_in_editor( $index ); $disabled = $this->get_disable_attribute( $index ); $choices = SCF::choices_eol_to_array( $this->get( 'choices' ) ); $direction = $this->get( 'check_direction' ); $form_field = sprintf( '', esc_attr( $name ), disabled( true, $disabled, false ) ); foreach ( $choices as $key => $choice ) { $choice = trim( $choice ); if ( ! SCF::is_assoc( $choices ) ) { $key = $choice; } $form_field .= sprintf( '', esc_attr( SCF_Config::PREFIX . 'item-' . $direction ), esc_attr( $name . '[]' ), esc_attr( $key ), checked( true, is_array( $value ) && in_array( $key, $value, true ), false ), disabled( true, $disabled, false ), esc_html( $choice ) ); } return $form_field; } /** * Displaying the option fields in custom field settings page. * * @param int $group_key Group key. * @param int $field_key Field key. */ public function display_field_options( $group_key, $field_key ) { $this->display_label_option( $group_key, $field_key ); $this->display_name_option( $group_key, $field_key ); ?> value', 'smart-custom-fields' ); ?> __( 'horizontal', 'smart-custom-fields' ), 'vertical' => __( 'vertical', 'smart-custom-fields' ), ); foreach ( $directions as $key => $value ) { printf( '   ', esc_attr( $this->get_field_name_in_setting( $group_key, $field_key, 'check_direction' ) ), esc_attr( $key ), checked( $this->get( 'check_direction' ), $key, false ), esc_html( $value ) ); } ?> 'select', 'display-name' => __( 'Select', 'smart-custom-fields' ), 'optgroup' => 'select-fields', ); } /** * Set the non required items. * * @return array */ protected function options() { return array( 'choices' => '', 'default' => '', 'instruction' => '', 'notes' => '', ); } /** * Getting the field. * * @param int $index Field index. * @param string $value The value. * @return string */ public function get_field( $index, $value ) { $name = $this->get_field_name_in_editor( $index ); $disabled = $this->get_disable_attribute( $index ); $choices = SCF::choices_eol_to_array( $this->get( 'choices' ) ); $form_field = ''; foreach ( $choices as $key => $choice ) { $choice = trim( $choice ); if ( ! SCF::is_assoc( $choices ) ) { $key = $choice; } $form_field .= sprintf( '', esc_attr( $key ), selected( $value, $key, false ), esc_html( $choice ) ); } return sprintf( '', esc_attr( $name ), disabled( true, $disabled, false ), $form_field ); } /** * Displaying the option fields in custom field settings page. * * @param int $group_key Group key. * @param int $field_key Field key. */ public function display_field_options( $group_key, $field_key ) { $this->display_label_option( $group_key, $field_key ); $this->display_name_option( $group_key, $field_key ); ?> value', 'smart-custom-fields' ); ?> 'datepicker', 'display-name' => __( 'Date picker', 'smart-custom-fields' ), 'optgroup' => 'other-fields', ); } /** * Set the non required items. * * @return array */ protected function options() { return array( 'date_format' => '', 'max_date' => '', 'min_date' => '', 'default' => '', 'instruction' => '', 'notes' => '', ); } /** * Loading resources for editor. */ public function editor_enqueue_scripts() { global $wp_scripts; $ui = $wp_scripts->query( 'jquery-ui-core' ); wp_enqueue_style( 'jquery.ui', '//ajax.googleapis.com/ajax/libs/jqueryui/' . $ui->ver . '/themes/smoothness/jquery-ui.min.css', array(), $ui->ver ); wp_enqueue_script( 'jquery-ui-datepicker' ); wp_enqueue_script( SCF_Config::PREFIX . 'editor-datepicker', SMART_CUSTOM_FIELDS_URL . '/js/editor-datepicker.js', array( 'jquery', 'jquery-ui-datepicker' ), filemtime( SMART_CUSTOM_FIELDS_PATH . '/js/editor-datepicker.js' ), true ); } /** * Loading resources for editor for custom field settings page. */ public function settings_enqueue_scripts() { global $wp_scripts; $ui = $wp_scripts->query( 'jquery-ui-core' ); wp_enqueue_style( 'jquery.ui', '//ajax.googleapis.com/ajax/libs/jqueryui/' . $ui->ver . '/themes/smoothness/jquery-ui.min.css', array(), $ui->ver ); wp_enqueue_script( 'jquery-ui-datepicker' ); wp_enqueue_script( SCF_Config::PREFIX . 'settings-datepicker', SMART_CUSTOM_FIELDS_URL . '/js/settings-datepicker.js', array( 'jquery', 'jquery-ui-datepicker' ), filemtime( SMART_CUSTOM_FIELDS_PATH . '/js/settings-datepicker.js' ), true ); } /** * Getting the field. * * @param int $index Field index. * @param string $value The value. * @return string */ public function get_field( $index, $value ) { $name = $this->get_field_name_in_editor( $index ); $disabled = $this->get_disable_attribute( $index ); $data_js = $this->get_data_js(); return sprintf( '', esc_attr( $name ), esc_attr( $value ), esc_attr( SCF_Config::PREFIX . 'datepicker' ), disabled( true, $disabled, false ), $data_js ); } /** * Displaying the option fields in custom field settings page. * * @param int $group_key Group key. * @param int $field_key Field key. */ public function display_field_options( $group_key, $field_key ) { $this->display_label_option( $group_key, $field_key ); $this->display_name_option( $group_key, $field_key ); ?>
    , %2$s: esc_html__( 'Prease see %1$sdateFormat%1$s', 'smart-custom-fields' ), '', '' ); ?>
    , %2$s: esc_html__( 'Prease see %1$smaxData%2$s', 'smart-custom-fields' ), '', '' ); ?>
    , %2$s: esc_html__( 'Prease see %1$sminData%2$s', 'smart-custom-fields' ), '', '' ); ?> true, 'changeYear' => true, 'changeMonth' => true, ); // If locale is Japanese, change in Japanese notation if ( get_locale() === 'ja' ) { $js = array_merge( $js, array( 'yearSuffix' => '年', 'dateFormat' => 'yy-mm-dd', 'dayNames' => array( '日曜日', '月曜日', '火曜日', '水曜日', '木曜日', '金曜日', '土曜日', ), 'dayNamesMin' => array( '日', '月', '火', '水', '木', '金', '土', ), 'dayNamesShort' => array( '日曜', '月曜', '火曜', '水曜', '木曜', '金曜', '土曜', ), 'monthNames' => array( '1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月', ), 'monthNamesShort' => array( '1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月', ), ) ); } if ( $this->get( 'date_format' ) ) { $js['dateFormat'] = $this->get( 'date_format' ); } if ( $this->get( 'max_date' ) ) { $js['maxDate'] = $this->get( 'max_date' ); } if ( $this->get( 'min_date' ) ) { $js['minDate'] = $this->get( 'min_date' ); } return wp_json_encode( $js ); } } fields/class.field-wysiwyg.php000064400000014434146731356360012456 0ustar00 'wysiwyg', 'display-name' => __( 'Wysiwyg', 'smart-custom-fields' ), 'optgroup' => 'content-fields', ); } /** * Set the non required items. * * @return array */ protected function options() { return array( 'default' => '', 'instruction' => '', 'notes' => '', ); } /** * Loading js after loading TinyMCE in editor page. */ public function editor_enqueue_scripts() { add_action( 'after_wp_tiny_mce', array( $this, 'after_wp_tiny_mce' ) ); } /** * Add script for wysiwyg. */ public function after_wp_tiny_mce() { // phpcs:disable WordPress.WP.EnqueuedResources.NonEnqueuedScript printf( '', esc_url( plugins_url( SCF_Config::NAME ) . '/js/editor-wysiwyg.js' ) ); // phpcs:enable } /** * Processing to be executed immediately after the field initialization. * If not exec this, taxonomy and profile wysiwyg has js error. */ protected function after_loaded() { add_action( 'admin_footer', array( $this, 'admin_footer' ) ); } /** * Add dummy editor. */ public function admin_footer() { ?>
    get_field_name_in_editor( $index ); $wysiwyg_id = str_replace( array( '[', ']', '-' ), '_', $name ); $disabled = $this->get_disable_attribute( $index ); $value = format_for_editor( $value ); return sprintf( '
    %1$s
    ', $this->media_buttons( $wysiwyg_id ), esc_attr( $wysiwyg_id ), esc_attr( $name ), disabled( true, $disabled, false ), $value, esc_html__( 'Visual', 'smart-custom-fields' ), esc_html__( 'Text', 'smart-custom-fields' ) ); } /** * Displaying the option fields in custom field settings page. * * @param int $group_key Group key. * @param int $field_key Field key. */ public function display_field_options( $group_key, $field_key ) { $this->display_label_option( $group_key, $field_key ); $this->display_name_option( $group_key, $field_key ); ?> '; return sprintf( '%s', esc_attr( $editor_id ), // phpcs:ignore WordPress.WP.I18n.MissingArgDomain esc_attr__( 'Add Media' ), // phpcs:ignore WordPress.WP.I18n.MissingArgDomain $img . __( 'Add Media' ) ); } /** * Validating when displaying meta data. * * @param mixed $value The value. * @param string $field_type Field type. * @return string|array */ public function validate_get_value( $value, $field_type ) { if ( $field_type === $this->get_attribute( 'type' ) ) { if ( is_array( $value ) ) { $validated_value = array(); foreach ( $value as $k => $v ) { $validated_value[ $k ] = $this->add_the_content_filter( $v ); } $value = $validated_value; } else { $value = $this->add_the_content_filter( $value ); } } return $value; } /** * Hooking functions that is hooked to the_content. * * @param string $value The value. * @return string */ protected function add_the_content_filter( $value ) { if ( has_filter( 'the_content', 'wptexturize' ) ) { $value = wptexturize( $value ); } if ( has_filter( 'the_content', 'convert_smilies' ) ) { $value = convert_smilies( $value ); } if ( has_filter( 'the_content', 'convert_chars' ) ) { $value = convert_chars( $value ); } if ( has_filter( 'the_content', 'wpautop' ) ) { $value = wpautop( $value ); } if ( has_filter( 'the_content', 'shortcode_unautop' ) ) { $value = shortcode_unautop( $value ); } if ( has_filter( 'the_content', 'prepend_attachment' ) ) { $value = prepend_attachment( $value ); } return $value; } } fields/class.field-image.php000064400000010036146731356360012010 0ustar00 'image', 'display-name' => __( 'Image', 'smart-custom-fields' ), 'optgroup' => 'content-fields', ); } /** * Set the non required items. * * @return array */ protected function options() { return array( 'instruction' => '', 'notes' => '', 'size' => 'full', ); } /** * Getting the field. * * @param int $index Field index. * @param string $value The value. * @return string */ public function get_field( $index, $value ) { $name = $this->get_field_name_in_editor( $index ); $disabled = $this->get_disable_attribute( $index ); $btn_remove = sprintf( '%s', esc_html__( 'Delete', 'smart-custom-fields' ) ); $hide_class = 'hide'; $image = $btn_remove; if ( $value ) { // Usually, $value is attachment ID. // If a customized, for example, $value is not an ID, // Regarded the $value is file URL. if ( preg_match( '/^\d+$/', $value ) ) { $image_src = wp_get_attachment_image_src( $value, $this->get( 'size' ) ); $image_alt = get_the_title( $value ); if ( is_array( $image_src ) && isset( $image_src[0] ) ) { $image_src = $image_src[0]; } } else { $image_url = $value; $path = str_replace( home_url(), '', $value ); $image_path = ABSPATH . untrailingslashit( $path ); if ( file_exists( $image_path ) ) { $wp_check_filetype = wp_check_filetype( $image_path ); if ( ! empty( $wp_check_filetype['type'] ) ) { $image_src = $image_url; } } } if ( $image_src && ! is_array( $image_src ) ) { $image = sprintf( '%s%s', esc_url( $image_src ), $image_alt, $btn_remove ); $hide_class = ''; } } return sprintf( '%s
    %s ', esc_html__( 'Image Select', 'smart-custom-fields' ), esc_attr( SCF_Config::PREFIX . 'upload-image' ), esc_attr( $hide_class ), esc_attr( $this->get( 'size' ) ), $image, esc_attr( $name ), esc_attr( $value ), disabled( true, $disabled, false ) ); } /** * Displaying the option fields in custom field settings page. * * @param int $group_key Group key. * @param int $field_key Field key. */ public function display_field_options( $group_key, $field_key ) { $this->display_label_option( $group_key, $field_key ); $this->display_name_option( $group_key, $field_key ); ?> 'message', 'display-name' => __( 'Message', 'smart-custom-fields' ), 'optgroup' => 'basic-fields', 'allow-multiple-data' => false, 'layout' => 'full-width', ); } /** * Set the non required items. * * @return array */ protected function options() { return array( 'default' => '', 'notes' => '', ); } /** * Getting the field. * * @param int $index Field index. * @param string $value The value. * @return string */ public function get_field( $index, $value ) { $name = $this->get_field_name_in_editor( $index ); $disabled = $this->get_disable_attribute( $index ); return sprintf( '
    %s
    ', esc_attr( $name ), disabled( true, $disabled, false ), $value ); } /** * Displaying the option fields in custom field settings page. * * @param int $group_key Group key. * @param int $field_key Field key. */ public function display_field_options( $group_key, $field_key ) { $this->display_name_option( $group_key, $field_key ); ?> 'colorpicker', 'display-name' => __( 'Color picker', 'smart-custom-fields' ), 'optgroup' => 'other-fields', ); } /** * Set the non required items. * * @return array */ protected function options() { return array( 'default' => '', 'instruction' => '', 'notes' => '', ); } /** * Loading resources for editor. */ public function editor_enqueue_scripts() { wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_script( SCF_Config::PREFIX . 'editor-colorpicker', SMART_CUSTOM_FIELDS_URL . '/js/editor-colorpicker.js', array( 'jquery', 'wp-color-picker' ), filemtime( SMART_CUSTOM_FIELDS_PATH . '/js/editor-colorpicker.js' ), true ); } /** * Loading resources for editor for custom field settings page. */ public function settings_enqueue_scripts() { wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_script( SCF_Config::PREFIX . 'settings-colorpicker', SMART_CUSTOM_FIELDS_URL . '/js/settings-colorpicker.js', array( 'jquery', 'wp-color-picker' ), filemtime( SMART_CUSTOM_FIELDS_PATH . '/js/settings-colorpicker.js' ), true ); } /** * Getting the field. * * @param int $index Field index. * @param string $value The value. * @return string */ public function get_field( $index, $value ) { $name = $this->get_field_name_in_editor( $index ); $disabled = $this->get_disable_attribute( $index ); return sprintf( '', esc_attr( $name ), esc_attr( $value ), esc_attr( SCF_Config::PREFIX . 'colorpicker' ), disabled( true, $disabled, false ) ); } /** * Displaying the option fields in custom field settings page. * * @param int $group_key Group key. * @param int $field_key Field key. */ public function display_field_options( $group_key, $field_key ) { $this->display_label_option( $group_key, $field_key ); $this->display_name_option( $group_key, $field_key ); ?> get_meta( $wp_object, $name ) ) { self::debug_cache_message( "use get cache. [name: {$name}]" ); return $cache->get_meta( $wp_object, $name ); } else { self::debug_cache_message( "dont use get cache... [name: {$name}]" ); } $settings = self::get_settings( $wp_object ); foreach ( $settings as $setting ) { // If $name matches the group name, returns fields in the group as array. $group = $setting->get_group( $name ); if ( $group ) { $values_by_group = self::get_values_by_group( $wp_object, $group ); $cache->save_meta( $wp_object, $name, $values_by_group ); return $values_by_group; } // If $name doesn't matche the group name, returns the field that matches. $groups = $setting->get_groups(); foreach ( $groups as $group ) { $field = $group->get_field( $name ); if ( $field ) { $is_repeatable = $group->is_repeatable(); $value_by_field = self::get_value_by_field( $wp_object, $field, $is_repeatable ); $cache->save_meta( $wp_object, $name, $value_by_field ); return $value_by_field; } } } } /** * Getting all of any meta data to feel good. * * @param WP_Post|WP_User|WP_Term|stdClass $wp_object Object meta object. * @return mixed */ protected static function get_all_meta( $wp_object ) { $cache = Smart_Custom_Fields_Cache::get_instance(); $settings = self::get_settings( $wp_object ); $post_meta = array(); foreach ( $settings as $setting ) { $groups = $setting->get_groups(); foreach ( $groups as $group ) { $is_repeatable = $group->is_repeatable(); $group_name = $group->get_name(); if ( $is_repeatable && $group_name ) { $values_by_group = self::get_values_by_group( $wp_object, $group ); $cache->save_meta( $wp_object, $group_name, $values_by_group ); $post_meta[ $group_name ] = $values_by_group; } else { $fields = $group->get_fields(); foreach ( $fields as $field ) { $field_name = $field->get( 'name' ); $value_by_field = self::get_value_by_field( $wp_object, $field, $is_repeatable ); $cache->save_meta( $wp_object, $field_name, $value_by_field ); $post_meta[ $field_name ] = $value_by_field; } } } } return $post_meta; } /** * If in preview, return the preview post ID. * * @param int $post_id Post id. * @return int */ protected static function get_real_post_id( $post_id ) { if ( is_preview() ) { $preview_post = wp_get_post_autosave( $post_id ); if ( isset( $preview_post->ID ) ) { $post_id = $preview_post->ID; } } return $post_id; } /** * Getting the meta data of the group. * When group, Note the point that returned data are repetition. * * @param WP_Post|WP_User|WP_Term|stdClass $wp_object Object meta object. * @param Smart_Custom_Fields_Group $group Group object. * @return mixed */ protected static function get_values_by_group( $wp_object, $group ) { $is_repeatable = $group->is_repeatable(); $meta = array(); $fields = $group->get_fields(); foreach ( $fields as $field ) { if ( $field->get_attribute( 'allow-multiple-data' ) ) { $meta[0][ $field->get( 'name' ) ] = array(); } else { $meta[0][ $field->get( 'name' ) ] = ''; } } $default_meta = $meta[0]; foreach ( $fields as $field ) { $value_by_field = self::get_value_by_field( $wp_object, $field, $is_repeatable ); foreach ( $value_by_field as $i => $value ) { $meta[ $i ][ $field->get( 'name' ) ] = $value; } } foreach ( $meta as $i => $value ) { $meta[ $i ] = array_merge( $default_meta, $value ); } return $meta; } /** * Getting the meta data of the field. * * @param WP_Post|WP_User|WP_Term|stdClass $wp_object Object meta object. * @param Smart_Custom_Fields_Field_Base $field Field object. * @param bool $is_repeatable Whether the group that this field belongs is repetition. * @return mixed $post_meta */ protected static function get_value_by_field( $wp_object, $field, $is_repeatable ) { $field_name = $field->get( 'name' ); if ( ! $field_name ) { return; } $meta = new Smart_Custom_Fields_Meta( $wp_object ); // In the case of multi-value items in the loop $field_type = $field->get_attribute( 'type' ); $repeat_multiple_data = self::get_repeat_multiple_data( $wp_object ); if ( is_array( $repeat_multiple_data ) && isset( $repeat_multiple_data[ $field_name ] ) ) { if ( $meta->is_saved_the_key( $field_name ) ) { $_meta = $meta->get( $field_name ); } else { $_meta = self::get_default_value( $field ); } $start = 0; $meta_value = array(); foreach ( $repeat_multiple_data[ $field_name ] as $repeat_multiple_key => $repeat_multiple_value ) { if ( 0 === $repeat_multiple_value ) { $value = array(); } else { $value = array_slice( $_meta, $start, $repeat_multiple_value ); $start += $repeat_multiple_value; } $value = apply_filters( SCF_Config::PREFIX . 'validate-get-value', $value, $field_type ); $meta_value[ $repeat_multiple_key ] = $value; } } else { // Other than that $single = true; if ( $field->get_attribute( 'allow-multiple-data' ) || $is_repeatable ) { $single = false; } if ( $meta->is_saved_the_key( $field_name ) ) { $meta_value = $meta->get( $field_name, $single ); } else { $meta_value = self::get_default_value( $field, $single ); } $meta_value = apply_filters( SCF_Config::PREFIX . 'validate-get-value', $meta_value, $field_type ); } return $meta_value; } /** * Return the default value. * * @param Smart_Custom_Fields_Field_Base $field Field object. * @param bool $single Whether to return a single value. This parameter has no effect if $key is not specified. * @return array|strings */ public static function get_default_value( $field, $single = false ) { if ( ! is_a( $field, 'Smart_Custom_Fields_Field_Base' ) ) { if ( $single ) { return ''; } return array(); } $choices = $field->get( 'choices' ); $default = $field->get( 'default' ); if ( $field->get_attribute( 'allow-multiple-data' ) ) { $choices = self::choices_eol_to_array( $choices ); $default = self::choices_eol_to_array( $default ); $default_sanitized = array(); if ( self::is_assoc( $choices ) ) { $_choices = array_flip( $choices ); } else { $_choices = $choices; } foreach ( $default as $key => $value ) { if ( in_array( $value, $_choices, true ) ) { if ( preg_match( '/^\d+$/', $value ) ) { $value = (int) $value; } $default_sanitized[ $key ] = $value; } } return $default_sanitized; } if ( $single ) { // Return string return $default; } else { // Return array if ( is_array( $default ) ) { return $default; } if ( '' === $default || false === $default || null === $default ) { return array(); } return (array) $default; } } /** * Getting enabled custom field settings in the post type or the role or the term. * * @param WP_Post|WP_User|WP_Term|stdClass $wp_object Object meta object. * @return array */ public static function get_settings_posts( $wp_object ) { $cache = Smart_Custom_Fields_Cache::get_instance(); $settings_posts = array(); if ( null !== $cache->get_settings_posts( $wp_object ) ) { self::debug_cache_message( 'use settings posts cache.' ); return $cache->get_settings_posts( $wp_object ); } else { self::debug_cache_message( 'dont use settings posts cache...' ); } $meta = new Smart_Custom_Fields_Meta( $wp_object ); $types = $meta->get_types( false ); switch ( $meta->get_meta_type() ) { case 'post': $key = SCF_Config::PREFIX . 'condition'; break; case 'user': $key = SCF_Config::PREFIX . 'roles'; break; case 'term': $key = SCF_Config::PREFIX . 'taxonomies'; break; case 'option': $key = SCF_Config::PREFIX . 'options-pages'; break; default: $key = ''; } if ( ! empty( $key ) && ( ! empty( $types ) ) ) { $meta_query = array(); foreach ( $types as $type ) { $meta_query[] = array( 'key' => $key, 'value' => sprintf( '"%s"', $type ), 'compare' => 'LIKE', ); } if ( $meta_query ) { $meta_query['relation'] = 'OR'; } $args = array( 'post_type' => SCF_Config::NAME, 'posts_per_page' => -1, 'order' => 'ASC', 'order_by' => 'menu_order', 'meta_query' => $meta_query, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query ); $settings_posts = get_posts( $args ); } $cache = Smart_Custom_Fields_Cache::get_instance(); $cache->save_settings_posts( $wp_object, $settings_posts ); return $settings_posts; } /** * Getting array of the Setting object. * * @param WP_Post|WP_User|WP_Term|stdClass $wp_object Object meta object. * @return array */ public static function get_settings( $wp_object ) { $meta = new Smart_Custom_Fields_Meta( $wp_object ); $id = $meta->get_id(); $type = $meta->get_type( false ); $types = $meta->get_types( false ); $meta_type = $meta->get_meta_type(); // IF the post that has custom field settings according to post ID, // don't display because the post ID would change in preview. // So if in preview, re-getting post ID from original post (parent of the preview). if ( 'post' === $meta_type && 'revision' === $wp_object->post_type ) { $wp_object = get_post( $wp_object->post_parent ); } $settings = array(); if ( ! empty( $types ) ) { $settings_posts = self::get_settings_posts( $wp_object ); if ( 'post' === $meta_type ) { $settings = self::get_settings_for_post( $wp_object, $settings_posts ); } elseif ( 'user' === $meta_type ) { $settings = self::get_settings_for_profile( $wp_object, $settings_posts ); } elseif ( 'term' === $meta_type ) { $settings = self::get_settings_for_term( $wp_object, $settings_posts ); } elseif ( 'option' === $meta_type ) { $settings = self::get_settings_for_option( $wp_object, $settings_posts ); } } $settings = apply_filters( SCF_Config::PREFIX . 'register-fields', $settings, $type, $id, $meta_type, $types ); if ( ! is_array( $settings ) ) { $settings = array(); } return $settings; } /** * Getting the Setting object for post. * * @param WP_Post $wp_object WP_Post object. * @param array $settings_posts Settings. * @return array */ protected static function get_settings_for_post( $wp_object, $settings_posts ) { $cache = Smart_Custom_Fields_Cache::get_instance(); $settings = array(); foreach ( $settings_posts as $settings_post ) { if ( $cache->get_settings( $settings_post->ID ) !== null ) { self::debug_cache_message( "use settings cache. [id: {$settings_post->ID}]" ); $setting = $cache->get_settings( $settings_post->ID, $wp_object ); if ( $setting ) { $settings[ $settings_post->ID ] = $setting; } continue; } self::debug_cache_message( "dont use settings cache... [SCF ID: {$settings_post->ID}] [post_type: {$wp_object->post_type}] [Post ID: {$wp_object->ID}]" ); $condition_post_ids_raw = get_post_meta( $settings_post->ID, SCF_Config::PREFIX . 'condition-post-ids', true ); if ( $condition_post_ids_raw ) { $condition_post_ids_raw = explode( ',', $condition_post_ids_raw ); foreach ( $condition_post_ids_raw as $condition_post_id ) { $condition_post_id = trim( $condition_post_id ); $setting = self::add_setting( $settings_post->ID, $settings_post->post_title ); if ( (int) $wp_object->ID === (int) $condition_post_id ) { $settings[ $settings_post->ID ] = $setting; } $post = get_post( $condition_post_id ); if ( empty( $post ) ) { $post = self::generate_post_object( $condition_post_id ); } $cache->save_settings( $settings_post->ID, $setting, $post ); } } else { $setting = self::add_setting( $settings_post->ID, $settings_post->post_title ); $settings[ $settings_post->ID ] = $setting; $cache->save_settings( $settings_post->ID, $setting ); } } return $settings; } /** * Getting the Setting object for user. * * @param WP_User|WP_Term|stdClass $wp_object Object meta object. * @param array $settings_posts Settings. * @return array */ protected static function get_settings_for_profile( $wp_object, $settings_posts ) { $cache = Smart_Custom_Fields_Cache::get_instance(); $settings = array(); foreach ( $settings_posts as $settings_post ) { if ( $cache->get_settings( $settings_post->ID ) !== null ) { self::debug_cache_message( "use settings cache. [id: {$settings_post->ID}]" ); $settings[] = $cache->get_settings( $settings_post->ID ); continue; } self::debug_cache_message( "dont use settings cache... [id: {$settings_post->ID}]" ); $setting = self::add_setting( $settings_post->ID, $settings_post->post_title ); $settings[] = $setting; $cache->save_settings( $settings_post->ID, $setting ); } return $settings; } /** * Getting the Setting object for term. * * @param WP_Term $wp_object WP_Term object. * @param array $settings_posts Settings. * @return array */ protected static function get_settings_for_term( $wp_object, $settings_posts ) { return self::get_settings_for_profile( $wp_object, $settings_posts ); } /** * Getting the Setting object for option. * * @param stdClass $wp_object stdClass object. * @param array $settings_posts Settings. * @return array */ protected static function get_settings_for_option( $wp_object, $settings_posts ) { return self::get_settings_for_profile( $wp_object, $settings_posts ); } /** * Getting delimited identification data of the repeated multi-value items. * * @param WP_Post|WP_User|WP_Term|stdClass $wp_object Object meta object. * @return array */ public static function get_repeat_multiple_data( $wp_object ) { $cache = Smart_Custom_Fields_Cache::get_instance(); $repeat_multiple_data = array(); if ( $cache->get_repeat_multiple_data( $wp_object ) ) { return $cache->get_repeat_multiple_data( $wp_object ); } $meta = new Smart_Custom_Fields_Meta( $wp_object ); $_repeat_multiple_data = $meta->get( SCF_Config::PREFIX . 'repeat-multiple-data', true ); if ( ! empty( $_repeat_multiple_data ) ) { $repeat_multiple_data = $_repeat_multiple_data; } $cache->save_repeat_multiple_data( $wp_object, $repeat_multiple_data ); return $repeat_multiple_data; } /** * Return true if null or empty value. * * @param mixed $value Value. * @return bool */ public static function is_empty( &$value ) { if ( isset( $value ) ) { if ( is_null( $value ) || '' === $value ) { return true; } return false; } return true; } /** * Whether the associative array or not. * * @see http://qiita.com/ka215/items/a14e53547e717d2a564f * * @param array $data This argument should be expected an array. * @param boolean $multidimensional True if a multidimensional array is inclusion into associative array, the default value is false. * @return boolean */ public static function is_assoc( $data, $multidimensional = false ) { if ( ! is_array( $data ) || empty( $data ) ) { return false; } $has_array = false; foreach ( $data as $key => $value ) { if ( is_array( $value ) ) { $has_array = true; } if ( ! is_int( $key ) ) { return true; } } return $multidimensional && $has_array ? true : false; } /** * Adding the available form field object. * * @param Smart_Custom_Fields_Field_Base $instance Field object. */ public static function add_form_field_instance( Smart_Custom_Fields_Field_Base $instance ) { $type = $instance->get_attribute( 'type' ); if ( ! empty( $type ) ) { self::$fields[ $type ] = $instance; } } /** * Getting the available form field object. * * @param string $type Type of the form field. * @return Smart_Custom_Fields_Field_Base */ public static function get_form_field_instance( $type ) { if ( ! empty( self::$fields[ $type ] ) ) { return clone self::$fields[ $type ]; } } /** * Getting all available form field object. * * @return array */ public static function get_form_field_instances() { $fields = array(); foreach ( self::$fields as $type => $instance ) { $fields[ $type ] = self::get_form_field_instance( $type ); } return $fields; } /** * Getting custom fields that saved custo field settings page. * Note that not return only one even define multiple fields with the same name of the field name. * * @param WP_Post|WP_User|WP_Term|stdClass $wp_object Object meta object. * @param string $field_name Field name. * @return Smart_Custom_Fields_Field_Base|null */ public static function get_field( $wp_object, $field_name ) { if ( '_locale' === $field_name || '_original_post' === $field_name ) { return null; } $settings = self::get_settings( $wp_object ); foreach ( $settings as $setting ) { $fields = $setting->get_fields(); if ( ! empty( $fields[ $field_name ] ) ) { return $fields[ $field_name ]; } } } /** * Convert to array from newline delimiter $choices. * * @param string $choices Choices. * @return array */ public static function choices_eol_to_array( $choices ) { if ( ! is_array( $choices ) ) { if ( '' === $choices || false === $choices || null === $choices ) { return array(); } $_choices = str_replace( array( "\r\n", "\r", "\n" ), "\n", $choices ); $_choices = explode( "\n", $_choices ); $choices = array(); foreach ( $_choices as $_choice ) { $_choice = array_map( 'trim', explode( '=>', $_choice ) ); if ( count( $_choice ) === 2 ) { $choices[ $_choice[0] ] = $_choice[1]; } else { $choices = array_merge( $choices, $_choice ); } } } return $choices; } /** * Return generated Setting object. * * @param string $id Post ID of custom field settings page. * @param string $title Title of custom field settings page. * @return Smart_Custom_Fields_Setting */ public static function add_setting( $id, $title ) { return new Smart_Custom_Fields_Setting( $id, $title ); } /** * Adding custom options page. * * @see https://developer.wordpress.org/reference/functions/add_menu_page/ * * @param string $page_title The text to be displayed in the title tags of the page when the menu is selected. * @param string $menu_title The text to be used for the menu. * @param string $capability The capability required for this menu to be displayed to the user. * @param string $menu_slug The slug name to refer to this menu by. Should be unique for this menu page and only include lowercase alphanumeric, dashes, and underscores characters to be compatible with sanitize_key(). * @param string $icon_url The URL to the icon to be used for this menu. * @param int $position The position in the menu order this item should appear. * @return string */ public static function add_options_page( $page_title, $menu_title, $capability, $menu_slug, $icon_url = '', $position = null ) { self::$options_pages[ $menu_slug ] = $menu_title; new Smart_Custom_Fields_Options_Page( $page_title, $menu_title, $capability, $menu_slug, $icon_url, $position ); return $menu_slug; } /** * Return array of custom options pages * * @return array */ public static function get_options_pages() { return self::$options_pages; } /** * Generate WP_Post object. * * @param int $post_id Post id. * @param string $post_type Post type. * @return WP_Post */ public static function generate_post_object( $post_id, $post_type = null ) { $post = new stdClass(); $post->ID = $post_id; $post->post_type = $post_type; return new WP_Post( $post ); } /** * Generate option object. * * @param string $menu_slug Menu slug. * @return stdClass */ public static function generate_option_object( $menu_slug ) { $options_pages = self::get_options_pages(); if ( ! isset( $options_pages[ $menu_slug ] ) ) { return; } $option = new stdClass(); $option->menu_slug = $menu_slug; $option->menu_title = $options_pages[ $menu_slug ]; return $option; } /** * Print cache usage. * * @param string $message Message. */ protected static function debug_cache_message( $message ) { if ( defined( 'SCF_DEBUG_CACHE' ) && SCF_DEBUG_CACHE === true ) { echo wp_kses_post( $message ) . '
    '; } } } models/class.group.php000064400000006450146731356360011023 0ustar00name = $group_name; $this->repeat = true === $repeat ? true : false; $fields = array(); foreach ( $_fields as $field_attributes ) { $field = SCF::get_form_field_instance( $field_attributes['type'] ); if ( ! is_a( $field, 'Smart_Custom_Fields_Field_Base' ) ) { continue; } foreach ( $field_attributes as $key => $value ) { $field->set( $key, $value ); } if ( ! empty( $field ) ) { $fields[ $field->get( 'name' ) ] = $field; } } $this->fields = $fields; } /** * Getting group name * * @return string */ public function get_name() { if ( is_numeric( $this->name ) ) { return; } return $this->name; } /** * Getting fields that saved in this settings page * * @return array */ public function get_fields() { return $this->fields; } /** * Getting the field. * * @param string $field_name Field name. * @return Smart_Custom_Fields_Field_Base|null */ public function get_field( $field_name ) { $fields = $this->get_fields(); if ( isset( $fields[ $field_name ] ) ) { return $fields[ $field_name ]; } } /** * Whether repeating group. * * @return bool */ public function is_repeatable() { return $this->repeat; } /** * Displaying "hide" if $repeatable is empty. * * @param string $repeatable Repeatable. */ private function add_hide_class( $repeatable ) { if ( ! $repeatable ) { echo 'hide'; } } /** * Displaying the option fields in custom field settings page ( Common ). * * @param int $group_key Group key. */ public function display_options( $group_key ) { ?>
    *
    restore( $revision ); } /** * リビジョンデータを保存 * *_post_meta はリビジョンIDのときに自動的に本物IDに変換して処理してしまうので、*_metadata を使うこと * * @param int $post_id The revision post id. */ public function wp_insert_post( $post_id ) { if ( ! isset( $_POST[ SCF_Config::NAME ] ) ) { return; } if ( ! wp_is_post_revision( $post_id ) ) { return; } $settings = SCF::get_settings( get_post( $post_id ) ); if ( ! $settings ) { return; } check_admin_referer( SCF_Config::NAME . '-fields', SCF_Config::PREFIX . 'fields-nonce' ); $meta = new Smart_Custom_Fields_Meta( get_post( $post_id ) ); $meta->save( $_POST ); } /** * プレビューのときはプレビューのメタデータを返す。ただし、アイキャッチはリビジョンが無いので除外する * * @param mixed $value The value to return, either a single metadata value or an array of values depending on the value of $single. Default null. * @param int $post_id ID of the object metadata is for. * @param string $meta_key Metadata key. * @param bool $single Whether to return only the first value of the specified $meta_key. * @return mixed */ public function get_post_metadata( $value, $post_id, $meta_key, $single ) { if ( ! is_preview() ) { return $value; } if ( is_null( SCF::get_field( get_post( $post_id ), $meta_key ) ) ) { return $value; } $preview_id = $this->get_preview_id( $post_id ); if ( $preview_id && '_thumbnail_id' !== $meta_key ) { if ( $post_id !== $preview_id ) { $value = get_post_meta( $preview_id, $meta_key, $single ); } } return $value; } /** * プレビューの Post ID を返す * * @param int $post_id The post id. * @return int */ protected function get_preview_id( $post_id ) { global $post; $preview_id = 0; if ( isset( $post->ID ) && intval( $post->ID ) === intval( $post_id ) ) { $preview = wp_get_post_autosave( $post_id ); if ( is_preview() && $preview ) { $preview_id = $preview->ID; } } return $preview_id; } /** * リビジョン比較画面でメタデータを表示させるためにキーを追加する * * @param array $fields List of fields to revision. Contains 'post_title', 'post_content', and 'post_excerpt' by default. * @return array */ public function _wp_post_revision_fields( $fields ) { $fields[ SCF_Config::PREFIX . 'debug-preview' ] = esc_html__( 'Smart Custom Fields', 'smart-custom-fields' ); return $fields; } /** * プレビュー時にメタデータを保存するためにキーとなる項目を出力する */ public function edit_form_after_title() { printf( '', esc_attr( SCF_Config::PREFIX . 'debug-preview' ) ); } /** * Display metadata on revision comparison screen. * * @param string $value The current revision field to compare to or from. * @param string $column The current revision field. * @param WP_Post $post The revision post object to compare to or from. * @return string */ public function _wp_post_revision_field_debug_preview( $value, $column, $post ) { $output = ''; $values = SCF::gets( $post->ID ); foreach ( $values as $field_name_or_group_name => $value ) { $output .= sprintf( "■ %s\n", $field_name_or_group_name ); if ( is_array( $value ) ) { if ( isset( $value[0] ) && is_array( $value[0] ) ) { foreach ( $value as $i => $repeat_data_values ) { $output .= sprintf( "- #%s\n", $i ); foreach ( $repeat_data_values as $field_name => $repeat_data_value ) { $output .= sprintf( ' %s: ', $field_name ); if ( is_array( $repeat_data_value ) ) { $output .= sprintf( "[%s]\n", implode( ', ', $repeat_data_value ) ); } else { $output .= sprintf( "%s\n", $repeat_data_value ); } } } } else { $output .= sprintf( "[%s]\n", implode( ', ', $value ) ); } } else { $output .= sprintf( "%s\n", $value ); } } return $output; } /** * If false, it is saved as a revision. * * @param bool $check_for_changes Whether to check for changes before saving a new revision. Default true. * @param WP_Post $last_revision The last revision post object. * @param WP_Post $post The post object. * @return bool */ public function wp_save_post_revision_check_for_changes( $check_for_changes, $last_revision, $post ) { $post_meta = array(); $p = get_post_custom( $post->ID ); foreach ( $p as $key => $value ) { $v = SCF::get( $key ); if ( ! is_null( $v ) ) { $post_meta[ $key ][] = $v; } } $posted_data = filter_input( INPUT_POST, SCF_Config::NAME, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); if ( $posted_data && maybe_serialize( $post_meta ) !== maybe_serialize( $posted_data ) ) { return false; } return true; } } models/class.options-page.php000064400000005347146731356360012300 0ustar00page_title = $page_title; $this->menu_title = $menu_title; $this->capability = $capability; $this->menu_slug = $menu_slug; $this->icon_url = $icon_url; $this->position = $position; add_action( 'admin_menu', array( $this, 'add_options_page_menu' ) ); } /** * Add options page menu. */ public function add_options_page_menu() { return add_menu_page( $this->page_title, $this->menu_title, $this->capability, $this->menu_slug, array( $this, 'display' ), $this->icon_url, $this->position ); } /** * Display option. */ public function display() { $option = SCF::generate_option_object( filter_input( INPUT_GET, 'page' ) ); if ( ! $option ) { return; } ?>

    menu_title ); ?>

    '', // eg. text 'display-name' => '', // eg. Text 'optgroup' => 'other-fields', 'allow-multiple-data' => false, 'layout' => 'default', // or "full-width" (new attribute to choose layout type) ); /** * Options of this field * * @var array */ protected $options = array( 'name' => '', 'label' => '', ); /** * __construct */ public function __construct() { $attributes = array_merge( $this->attributes, $this->init() ); $options = array_merge( $this->options, $this->options() ); if ( empty( $attributes['type'] ) || empty( $attributes['display-name'] ) ) { exit( 'This field object is invalid. Field object must have type and display-name attributes.' ); } if ( empty( $attributes['optgroup'] ) ) { $attributes['optgroup'] = 'basic-fields'; } $this->attributes = $attributes; $this->options = $options; add_filter( SCF_Config::PREFIX . 'field-select-' . $attributes['optgroup'], array( $this, 'field_select' ) ); $this->after_loaded(); SCF::add_form_field_instance( $this ); } /** * Set the required items * * @return array */ abstract protected function init(); /** * Set the non required items * * @return array */ abstract protected function options(); /** * Processing to be executed immediately after the field initialization */ protected function after_loaded() { } /** * Getting the field. * * @param int $index Field index. * @param mixed $value Field value. * @return string */ abstract public function get_field( $index, $value ); /** * Adding the type of this field to fields selection in custom field settings page. * * @param array $attributes List of fields that belong to the optgroup. * @return array */ public function field_select( $attributes ) { $attributes[ $this->get_attribute( 'type' ) ] = $this->get_attribute( 'display-name' ); return $attributes; } /** * Displaying the option fields in custom field settings page ( Common ). * * @param int $group_key Group key. * @param int $field_key Field key. */ public function display_options( $group_key, $field_key ) { $fields = SCF::get_form_field_instances(); foreach ( $fields as $field ) { if ( $field->get_attribute( 'type' ) === $this->get_attribute( 'type' ) ) { foreach ( $this->options as $key => $value ) { $field->set( $key, $value ); } } $field->_display_field_options( $group_key, $field_key ); } } /** * Displaying the name in custom field settings page. * * @param int $group_key Group key. * @param int $field_key Field key. */ protected function display_name_option( $group_key, $field_key ) { ?> * display_field_options( $group_key, $field_key ); ?>
    get( 'name' ), $index ); } /** * Whether to disabled. * Return true only when the null because data that all users have saved when $index is not null * * @param string $index Field index. * @return bool */ protected function get_disable_attribute( $index ) { $disabled = false; if ( is_null( $index ) ) { $disabled = true; } return $disabled; } /** * Getting the name attribute in custom field settings page. * * @param int $group_key Group key. * @param int $field_key Field key. * @param string $name Field name. * @return string */ public function get_field_name_in_setting( $group_key, $field_key, $name ) { return sprintf( '%s[%s][fields][%s][%s]', SCF_Config::NAME, $group_key, $field_key, $name ); } /** * Getting saved option value. * * @param string $key Key of options of this field. * @return mixed */ public function get( $key ) { if ( array_key_exists( $key, $this->options ) ) { return $this->options[ $key ]; } } /** * Set option value. * * @param string $key Key of options of this field. * @param mixed $value Value of options of this field. */ public function set( $key, $value ) { if ( array_key_exists( $key, $this->options ) ) { $this->options[ $key ] = $value; } } /** * Getting the attribute value. * * @param string $key Internal attribute key. * @return mixed */ public function get_attribute( $key ) { if ( array_key_exists( $key, $this->attributes ) ) { return $this->attributes[ $key ]; } } } models/class.ajax.php000064400000001520146731356360010603 0ustar00delete_term_meta_for_wp43(); } } models/class.setting.php000064400000006474146731356360011352 0ustar00id = $id; $this->title = $title; $post_meta = get_post_meta( $this->get_id(), SCF_Config::PREFIX . 'setting', true ); if ( is_array( $post_meta ) ) { foreach ( $post_meta as $group ) { $group = shortcode_atts( array( 'group-name' => '', 'repeat' => false, 'fields' => array(), ), $group ); $this->add_group( $group['group-name'], $group['repeat'], $group['fields'] ); } } } /** * Getting the post ID. * * @return string */ public function get_id() { return $this->id; } /** * Getting the post title. * * @return string */ public function get_title() { return $this->title; } /** * Getting the group objects. * * @return array */ public function get_groups() { return $this->groups; } /** * Getting together the fields in each group. * * @return array */ public function get_fields() { $groups = $this->get_groups(); $fields = array(); foreach ( $groups as $group ) { $fields = array_merge( $fields, $group->get_fields() ); } return $fields; } /** * Adding group to the tail. * If the argument is not, adding an empty group. * * @param string $group_name Gruop name. * @param bool $repeat If repeat, set true. * @param array $fields Fields. */ public function add_group( $group_name = null, $repeat = false, array $fields = array() ) { $group = $this->new_group( $group_name, $repeat, $fields ); $group_name = $group->get_name(); if ( $group_name ) { $this->groups[ $group_name ] = $group; } else { $this->groups[] = $group; } } /** * Getting group. * * @param string $group_name Gruop name. * @return Smart_Custom_Fields_Group|false */ public function get_group( $group_name ) { $groups = $this->get_groups(); if ( isset( $groups[ $group_name ] ) && $groups[ $group_name ]->is_repeatable() ) { return $groups[ $group_name ]; } } /** * Adding group to the head. * If the argument is not, adding an empty group. * * @param string $group_name Gruop name. * @param bool $repeat If repeat, set true. * @param array $fields Fields. */ public function add_group_unshift( $group_name = null, $repeat = false, array $fields = array() ) { $group = $this->new_group( $group_name, $repeat, $fields ); array_unshift( $this->groups, $group ); } /** * Getting generated new group. * * @param string $group_name Gruop name. * @param bool $repeat If repeat, set true. * @param array $fields Fields. */ protected function new_group( $group_name, $repeat, $fields ) { return new Smart_Custom_Fields_Group( $group_name, $repeat, $fields ); } } models/class.meta.php000064400000035756146731356360010630 0ustar00object = $wp_object; if ( is_a( $wp_object, 'WP_Post' ) ) { $this->id = $wp_object->ID; $this->type = $wp_object->post_type; $this->types = array( $wp_object->post_type ); $this->meta_type = 'post'; } elseif ( is_a( $wp_object, 'WP_User' ) ) { $this->id = $wp_object->ID; $this->type = $wp_object->roles[0]; $this->types = array_unique( array_merge( $wp_object->roles, array_keys( $wp_object->caps ) ) ); $this->meta_type = 'user'; } elseif ( isset( $wp_object->term_id ) ) { $this->id = $wp_object->term_id; $this->type = $wp_object->taxonomy; $this->types = array( $wp_object->taxonomy ); $this->meta_type = 'term'; } elseif ( isset( $wp_object->menu_slug ) ) { $this->id = $wp_object->menu_slug; $this->type = $wp_object->menu_slug; $this->types = array( $wp_object->menu_slug ); $this->meta_type = 'option'; } elseif ( empty( $wp_object ) || is_wp_error( $wp_object ) ) { $this->id = null; $this->type = null; $this->types = null; $this->meta_type = null; } else { throw new Exception( sprintf( 'Invalid $wp_object type error. $wp_object is "%s".', esc_html( get_class( $wp_object ) ) ) ); } } /** * Getting the meta type * * @return string post or user or term or option */ public function get_meta_type() { return $this->meta_type; } /** * Getting object ID. When option, this is menu slug. * * @return int|string */ public function get_id() { return $this->id; } /** * Getting type ( Post type or Role or Taxonomy or Menu slug ). * * @deprecated * * @param bool $accept_revision If post type, whether allow revision post type. * @return string */ public function get_type( $accept_revision = true ) { if ( 'post' === $this->meta_type && ! $accept_revision ) { $public_post_type = $this->get_public_post_type( $this->id ); return $public_post_type[0]; } return $this->type; } /** * Getting type ( Post type or Role or Taxonomy or Menu slug ). * * @param bool $accept_revision If post type, whether allow revision post type. * @return array */ public function get_types( $accept_revision = true ) { if ( 'post' === $this->meta_type && ! $accept_revision ) { return $this->get_public_post_type( $this->id ); } return $this->types; } /** * Getting post type. * To feel good also Post ID of the revision. * * @param int $post_id Post id. * @return array */ protected function get_public_post_type( $post_id ) { $public_post_id = wp_is_post_revision( $post_id ); if ( $public_post_id ) { $post = get_post( $public_post_id ); } else { $post = get_post( $post_id ); } if ( ! empty( $post->post_type ) ) { return array( $post->post_type ); } return $this->types; } /** * Object with this meta data is whether saved. * Post ... If auto-draft, not saved (new posts in) * Profile or Taxonomy or option ... Since not display only after saving. * So if all of meta data is empty, * It is determined that not saved * * @return bool */ public function is_saved() { if ( 'post' === $this->meta_type && 'auto-draft' === get_post_status( $this->get_id() ) ) { return false; } if ( ! $this->get() ) { return false; } return true; } /** * The metadata is wheter saved. * * @param string $key Meta key. * @return bool */ public function is_saved_the_key( $key ) { if ( 'post' === $this->meta_type && 'auto-draft' === get_post_status( $this->get_id() ) ) { return false; } if ( _get_meta_table( $this->meta_type ) && ! $this->maybe_4_3_term_meta() ) { return metadata_exists( $this->meta_type, $this->id, $key ); } $option = get_option( $this->get_option_name() ); if ( is_array( $option ) ) { return array_key_exists( $key, $option ); } return false; } /** * Less than WordPress 4.4 compatibility for term meta. * More than 4.4 are saved in meta. So if that use the meta data. * * @return bool */ public function maybe_4_3_term_meta() { if ( 'term' === $this->meta_type ) { if ( ! get_metadata( $this->meta_type, $this->id ) && get_option( $this->get_option_name() ) ) { return true; } } return false; } /** * Getting the meta data. * * @param string|null $key Field key. * @param bool $single false ... return array, true ... return string. * @return string|array */ public function get( $key = '', $single = false ) { if ( _get_meta_table( $this->meta_type ) && ! $this->maybe_4_3_term_meta() ) { $meta = get_metadata( $this->meta_type, $this->id, $key, $single ); } else { $meta = $this->get_option_metadata( $key, $single ); } if ( SCF_Config::PREFIX . 'repeat-multiple-data' === $key ) { return $meta; } $settings = SCF::get_settings( $this->object ); if ( $key ) { foreach ( $settings as $setting ) { $fields = $setting->get_fields(); if ( ! empty( $fields[ $key ] ) ) { return $meta; } } } elseif ( is_array( $meta ) ) { $metas = array(); foreach ( $settings as $setting ) { $fields = $setting->get_fields(); foreach ( $meta as $meta_key => $meta_value ) { if ( isset( $fields[ $meta_key ] ) ) { $metas[ $meta_key ] = $meta[ $meta_key ]; } } } } if ( ! empty( $metas ) ) { return $metas; } if ( $single ) { return ''; } return array(); } /** * Getting option like meta data. * * @param string|null $key Option key. * @param bool $single false ... return array, true ... return string. * @return string|array */ protected function get_option_metadata( $key, $single ) { $option = get_option( $this->get_option_name() ); if ( ! $key ) { return $option; } if ( isset( $option[ $key ] ) ) { if ( $single && is_array( $option[ $key ] ) ) { if ( isset( $option[ $key ][0] ) ) { return $option[ $key ][0]; } } else { return $option[ $key ]; } } if ( $single ) { return ''; } return array(); } /** * Updating meta data. If the meta data not exist, adding it. * * @param string $key Option key. * @param mixed $value Option value. * @param mixed $prev_value If specified, it overwrites the only ones of this value. * @return int|false */ public function update( $key, $value, $prev_value = '' ) { $return = false; do_action( SCF_Config::PREFIX . '-before-save-' . $this->meta_type, $this->id, $key, $value ); $is_valid = apply_filters( SCF_Config::PREFIX . '-validate-save-' . $this->meta_type, $this->id, $key, $value ); if ( $is_valid ) { if ( _get_meta_table( $this->meta_type ) ) { $return = update_metadata( $this->meta_type, $this->id, $key, $value, $prev_value ); } else { $return = $this->update_option_metadata( $key, $value, $prev_value ); } } do_action( SCF_Config::PREFIX . '-after-save-' . $this->meta_type, $this->id, $key, $value ); return $return; } /** * Updating the option like meta data. If the meta data not exist, adding it. * * @param string $key Option key. * @param mixed $value Option value. * @param mixed $prev_value If specified, it overwrites the only ones of this value. * @return bool */ protected function update_option_metadata( $key, $value, $prev_value ) { $option_name = $this->get_option_name(); $option = get_option( $option_name ); if ( isset( $option[ $key ] ) ) { if ( '' !== $prev_value ) { foreach ( $option[ $key ] as $option_key => $option_value ) { if ( $prev_value === $option_value ) { $option[ $key ][ $option_key ] = $value; break; } } } else { foreach ( $option[ $key ] as $option_key => $option_value ) { $option[ $key ][ $option_key ] = $value; } } } else { $option[ $key ][] = $value; } $option = stripslashes_deep( $option ); return update_option( $option_name, $option, false ); } /** * Adding the meta data. * * @param string $key Option key. * @param mixed $value Option value. * @param bool $unique Whether the key to the unique. * @return int|false */ public function add( $key, $value, $unique = false ) { $return = false; do_action( SCF_Config::PREFIX . '-before-save-' . $this->meta_type, $this->id, $key, $value ); $is_valid = apply_filters( SCF_Config::PREFIX . '-validate-save-' . $this->meta_type, $this->id, $key, $value ); if ( $is_valid ) { if ( _get_meta_table( $this->meta_type ) ) { $return = add_metadata( $this->meta_type, $this->id, $key, $value, $unique ); } else { $return = $this->add_option_metadata( $key, $value, $unique ); } } do_action( SCF_Config::PREFIX . '-after-save-' . $this->meta_type, $this->id, $key, $value ); return $return; } /** * Adding the option like meta data. * * @param string $key Option key. * @param mixed $value Option value. * @param bool $unique Whether the key to the unique. * @return bool */ protected function add_option_metadata( $key, $value, $unique ) { $option_name = $this->get_option_name(); $option = get_option( $option_name ); if ( ! $unique || ! isset( $option[ $key ] ) ) { $option[ $key ][] = $value; $option = stripslashes_deep( $option ); return update_option( $option_name, $option, false ); } return false; } /** * Deleting the meta data. * * @param string $key Meta key. * @param mixed $value If specified, it deletes the only ones of this value. * @return bool */ public function delete( $key = '', $value = '' ) { if ( _get_meta_table( $this->meta_type ) ) { if ( $key ) { return delete_metadata( $this->meta_type, $this->id, $key, $value ); } } elseif ( $key ) { return $this->delete_option_metadata( $key, $value ); } return false; } /** * Deleting the option like meta data. * * @param string $key Option key. * @param mixed $value If specified, it deletes the only ones of this value. * @return bool */ protected function delete_option_metadata( $key, $value ) { $option_name = $this->get_option_name(); $option = get_option( $option_name ); if ( isset( $option[ $key ] ) && '' === $value ) { unset( $option[ $key ] ); return update_option( $option_name, $option ); } if ( isset( $option[ $key ] ) && '' !== $value ) { foreach ( $option[ $key ] as $option_key => $option_value ) { if ( $option_value === $value ) { unset( $option[ $key ][ $option_key ] ); } } return update_option( $option_name, $option ); } return false; } /** * Delete all term meta for less than WordPress 4.3. */ public function delete_term_meta_for_wp43() { $option_name = $this->get_option_name(); return delete_option( $option_name ); } /** * Saving the meta data based on the posted data. * * @param array $__post $_POST. */ public function save( array $__post ) { // For repeated multi-value items identification $repeat_multiple_data = array(); // Retruning empty value when multi-value is empty, it doesn't save $multiple_data_fields = array(); if ( is_null( $this->object ) ) { return; } $this->delete( SCF_Config::PREFIX . 'repeat-multiple-data' ); if ( ! isset( $__post[ SCF_Config::NAME ] ) ) { return; } $settings = SCF::get_settings( $this->object ); $saved_data = array(); foreach ( $settings as $setting ) { $groups = $setting->get_groups(); foreach ( $groups as $group ) { $fields = $group->get_fields(); foreach ( $fields as $field ) { $field_name = $field->get( 'name' ); if ( ! isset( $__post[ SCF_Config::NAME ][ $field_name ] ) ) { continue; } $saved_data[ $field_name ] = $__post[ SCF_Config::NAME ][ $field_name ]; $this->delete( $field_name ); if ( $field->get_attribute( 'allow-multiple-data' ) ) { $multiple_data_fields[] = $field_name; } if ( $group->is_repeatable() && $field->get_attribute( 'allow-multiple-data' ) ) { $repeat_multiple_data_fields = $saved_data[ $field_name ]; foreach ( $repeat_multiple_data_fields as $values ) { if ( is_array( $values ) ) { $repeat_multiple_data[ $field_name ][] = count( $values ); } else { $repeat_multiple_data[ $field_name ][] = 0; } } } } } } if ( $repeat_multiple_data ) { $this->update( SCF_Config::PREFIX . 'repeat-multiple-data', $repeat_multiple_data ); } foreach ( $saved_data as $name => $values ) { foreach ( $values as $value ) { if ( in_array( $name, $multiple_data_fields, true ) && '' === $value ) { continue; } if ( ! is_array( $value ) ) { $this->add( $name, $value ); } else { foreach ( $value as $val ) { $this->add( $name, $val ); } } } } } /** * Restore the data from the revision. * * @param WP_Post $revision The revision post. */ public function restore( $revision ) { if ( 'post' !== $this->meta_type || is_null( $this->object ) || ! is_a( $revision, 'WP_Post' ) ) { return; } $settings = SCF::get_settings( $this->object ); foreach ( $settings as $setting ) { $fields = $setting->get_fields(); foreach ( $fields as $field ) { $field_name = $field->get( 'name' ); $this->delete( $field_name ); $value = SCF::get( $field_name, $revision->ID ); if ( is_array( $value ) ) { foreach ( $value as $val ) { if ( is_array( $val ) ) { foreach ( $val as $v ) { // Repeated multi-value items $this->add( $field_name, $v ); } } else { // Repeated single-value items or Non repeated multi-value items $this->add( $field_name, $val ); } } } else { // Non repeated single-value item $this->add( $field_name, $value ); } } } $repeat_multiple_data = SCF::get_repeat_multiple_data( $revision ); $repeat_multiple_data_name = SCF_Config::PREFIX . 'repeat-multiple-data'; $this->delete( $repeat_multiple_data_name ); $this->update( $repeat_multiple_data_name, $repeat_multiple_data ); } /** * Getting option name for saved options table. * * @return string */ public function get_option_name() { return sprintf( '%s%s-%s-%d', SCF_Config::PREFIX, $this->meta_type, $this->type, $this->id ); } } models/class.cache.php000064400000017170146731356360010733 0ustar00clear_meta(); $this->clear_settings_posts(); $this->clear_settings(); $this->clear_repeat_multiple_data(); } /** * Saving to cache. * * @param WP_Post|WP_User|WP_Term|stdClass $wp_object Object type object. * @param string $name Cache name. * @param mixed $data Cache data. */ public function save_meta( $wp_object, $name, $data ) { $meta = new Smart_Custom_Fields_Meta( $wp_object ); $id = $meta->get_id(); $type = $meta->get_type(); $meta_type = $meta->get_meta_type(); if ( ! empty( $id ) && ! empty( $type ) && ! empty( $meta_type ) ) { $this->meta[ $meta_type . '_' . $type . '_' . $id ][ $name ] = $data; } } /** * Getting the cache. * * @param WP_Post|WP_User|WP_Term|stdClass $wp_object Object type object. * @param string $name Cache name. * @return mixed */ public function get_meta( $wp_object, $name = null ) { $meta = new Smart_Custom_Fields_Meta( $wp_object ); $id = $meta->get_id(); $type = $meta->get_type(); $meta_type = $meta->get_meta_type(); if ( ! empty( $id ) && ! empty( $type ) && ! empty( $meta_type ) ) { if ( is_null( $name ) ) { if ( isset( $this->meta[ $meta_type . '_' . $type . '_' . $id ] ) ) { return $this->meta[ $meta_type . '_' . $type . '_' . $id ]; } } elseif ( isset( $this->meta[ $meta_type . '_' . $type . '_' . $id ][ $name ] ) ) { return $this->meta[ $meta_type . '_' . $type . '_' . $id ][ $name ]; } } } /** * Clear caches. */ public function clear_meta() { $this->meta = array(); } /** * Saving to cache that enabled custom field settings in the post type or the role or the term. * * @param WP_Post|WP_User|WP_Term|stdClass $wp_object Object type object. * @param array $settings_posts Settings. */ public function save_settings_posts( $wp_object, $settings_posts ) { $meta = new Smart_Custom_Fields_Meta( $wp_object ); $type = $meta->get_type( false ); $meta_type = $meta->get_meta_type(); $this->settings_posts[ $meta_type . '_' . $type ] = $settings_posts; } /** * Getting cache that enabled custom field settings in the post type or the role or the term. * * @param WP_Post|WP_User|WP_Term|stdClass $wp_object Object type object. * @return array|null */ public function get_settings_posts( $wp_object ) { $meta = new Smart_Custom_Fields_Meta( $wp_object ); $type = $meta->get_type( false ); $meta_type = $meta->get_meta_type(); if ( isset( $this->settings_posts[ $meta_type . '_' . $type ] ) ) { return $this->settings_posts[ $meta_type . '_' . $type ]; } } /** * Clear the $settings_posts. */ public function clear_settings_posts() { $this->settings_posts = array(); } /** * Saving the Setting object to cache. * * @param int $settings_post_id Settings id. * @param Smart_Custom_Fields_Setting $setting Smart_Custom_Fields_Setting object. * @param WP_Post|WP_User|WP_Term|stdClass $wp_object Object type object. */ public function save_settings( $settings_post_id, $setting, $wp_object = null ) { if ( ! is_null( $wp_object ) ) { $meta = new Smart_Custom_Fields_Meta( $wp_object ); $id = $meta->get_id(); $meta_type = $meta->get_meta_type(); } if ( ! empty( $meta_type ) && ! empty( $id ) ) { $this->settings[ $settings_post_id ][ $meta_type . '_' . $id ] = $setting; } else { $this->settings[ $settings_post_id ][0] = $setting; } } /** * Getting the Setting object cache * If there isn't the custom field settings ... null * If there is custom field settings * If there is no data for the specified $meta_type + $id * There is a thing of the General ... Smart_Custom_Fields_Setting * There isn't a thing of the General ... false * If there the data for the specified $meta_type + $id ... Smart_Custom_Fields_Setting * * @param int $settings_post_id Settings id. * @param WP_Post|WP_User|WP_Term|stdClass $wp_object Object type object. * @return Smart_Custom_Fields_Setting|false|null */ public function get_settings( $settings_post_id, $wp_object = null ) { if ( ! is_null( $wp_object ) ) { $meta = new Smart_Custom_Fields_Meta( $wp_object ); $id = $meta->get_id(); $meta_type = $meta->get_meta_type(); } if ( isset( $this->settings[ $settings_post_id ] ) ) { $settings = $this->settings[ $settings_post_id ]; if ( ! empty( $id ) && ! empty( $meta_type ) && isset( $settings[ $meta_type . '_' . $id ] ) ) { return $settings[ $meta_type . '_' . $id ]; } if ( isset( $settings[0] ) ) { return $settings[0]; } return false; } } /** * Clear the $settings */ public function clear_settings() { $this->settings = array(); } /** * Saving the delimited identification data of the repeated multi-value items to cache. * * @param WP_Post|WP_User|WP_Term|stdClass $wp_object Object type object. * @param mixed $repeat_multiple_data Repeat multiple data. */ public function save_repeat_multiple_data( $wp_object, $repeat_multiple_data ) { $meta = new Smart_Custom_Fields_Meta( $wp_object ); $id = $meta->get_id(); $type = $meta->get_type(); $meta_type = $meta->get_meta_type(); if ( ! empty( $id ) && ! empty( $type ) && ! empty( $meta_type ) ) { $this->repeat_multiple_data[ $meta_type . '_' . $type . '_' . $id ] = $repeat_multiple_data; } } /** * Getting delimited identification data of the repeated multi-value items from cache. * * @param WP_Post|WP_User|WP_Term|stdClass $wp_object Object type object. * @return mixed */ public function get_repeat_multiple_data( $wp_object ) { $meta = new Smart_Custom_Fields_Meta( $wp_object ); $id = $meta->get_id(); $type = $meta->get_type(); $meta_type = $meta->get_meta_type(); if ( ! empty( $id ) && ! empty( $type ) ) { if ( isset( $this->repeat_multiple_data[ $meta_type . '_' . $type . '_' . $id ] ) ) { return $this->repeat_multiple_data[ $meta_type . '_' . $type . '_' . $id ]; } } } /** * Clear delimited identification data of the repeated multi-value items cache. */ public function clear_repeat_multiple_data() { $this->repeat_multiple_data = array(); } } class.config.php000064400000000610146731356360007641 0ustar00 esc_html__( 'Image setting', 'smart-custom-fields' ), 'file_uploader_title' => esc_html__( 'File setting', 'smart-custom-fields' ), ) ); do_action( SCF_Config::PREFIX . 'after-editor-enqueue-scripts', $hook ); if ( ! user_can_richedit() ) { wp_enqueue_script( 'tinymce', SMART_CUSTOM_FIELDS_URL . '/js/tinymce/tinymce.min.js', array(), filemtime( SMART_CUSTOM_FIELDS_PATH . '/js/tinymce/tinymce.min.js' ), true ); } } /** * Display custom fields in edit page. * * @param WP_Post|WP_User|WP_Term|stdClass $wp_object Object meta object. * @param array $callback_args Custom field setting information. */ public function display_meta_box( $wp_object, $callback_args ) { $groups = $callback_args['args']; $tables = $this->get_tables( $wp_object, $groups ); printf( '
    ', esc_attr( SCF_Config::PREFIX . 'meta-box' ) ); $index = 0; foreach ( $tables as $group_key => $group ) { $is_repeatable = $group->is_repeatable(); if ( $is_repeatable && 0 === $index ) { printf( '
    ', esc_attr( SCF_Config::PREFIX . 'meta-box-repeat-tables' ) ); $this->display_tr( $wp_object, $is_repeatable, $group->get_fields() ); } $this->display_tr( $wp_object, $is_repeatable, $group->get_fields(), $index ); // If in the loop, count up the index. // If exit the loop, reset the count. if ( $is_repeatable && isset( $tables[ $group_key + 1 ] ) && $group->get_name() === $tables[ $group_key + 1 ]->get_name() ) { ++$index; } else { $index = 0; } if ( $is_repeatable && 0 === $index ) { printf( '
    ' ); } } printf( '
    ' ); wp_nonce_field( SCF_Config::NAME . '-fields', SCF_Config::PREFIX . 'fields-nonce' ); } /** * Saving posted data. * * @param array $data Data. * @param WP_Post|WP_User|WP_Term|stdClass $wp_object Object meta object. */ protected function save( $data, $wp_object ) { check_admin_referer( SCF_Config::NAME . '-fields', SCF_Config::PREFIX . 'fields-nonce' ); $meta = new Smart_Custom_Fields_Meta( $wp_object ); $meta->save( $data ); } /** * Generating array for displaying the custom fields. * * @param WP_Post|WP_User|WP_Term|stdClass $wp_object Object meta object. * @param array $groups Settings from custom field settings page. * @return array Array for displaying a table for custom fields. */ protected function get_tables( $wp_object, $groups ) { $meta = new Smart_Custom_Fields_Meta( $wp_object ); $repeat_multiple_data = SCF::get_repeat_multiple_data( $wp_object ); $tables = array(); foreach ( $groups as $group ) { // If in the loop, Added groupgs by the amount of the loop. // Added only one if setting is repetition but not loop (Ex, new registration) if ( true === $group->is_repeatable() ) { $loop_count = 1; $fields = $group->get_fields(); foreach ( $fields as $field ) { $field_name = $field->get( 'name' ); $meta_value = $meta->get( $field_name ); if ( is_array( $meta_value ) ) { $meta_count = count( $meta_value ); // When the same name of the custom field is a multiple (checbox or loop) if ( $meta_count > 1 ) { // checkbox if ( $field->get_attribute( 'allow-multiple-data' ) ) { if ( is_array( $repeat_multiple_data ) && isset( $repeat_multiple_data[ $field_name ] ) ) { $repeat_multiple_data_count = count( $repeat_multiple_data[ $field_name ] ); if ( $loop_count < $repeat_multiple_data_count ) { $loop_count = $repeat_multiple_data_count; } } } elseif ( $loop_count < $meta_count ) { // other than checkbox $loop_count = $meta_count; } } } } if ( $loop_count >= 1 ) { for ( $i = $loop_count; $i > 0; $i-- ) { $tables[] = $group; } continue; } } $tables[] = $group; } return $tables; } /** * Getting the multi-value field meta data. * * @param WP_Post|WP_User|WP_Term|stdClass $wp_object Object meta object. * @param Smart_Custom_Fields_Field_Base $field Field object. * @param int $index Index of value. * @return array */ public function get_multiple_data_field_value( $wp_object, $field, $index ) { $meta = new Smart_Custom_Fields_Meta( $wp_object ); $field_name = $field->get( 'name' ); if ( is_null( $index ) ) { return SCF::get_default_value( $field ); } if ( ! $meta->is_saved_the_key( $field_name ) ) { return SCF::get_default_value( $field ); } $value = $meta->get( $field_name ); // in the loop $repeat_multiple_data = SCF::get_repeat_multiple_data( $wp_object ); if ( is_array( $repeat_multiple_data ) && isset( $repeat_multiple_data[ $field_name ] ) ) { $now_num = 0; if ( is_array( $repeat_multiple_data[ $field_name ] ) && isset( $repeat_multiple_data[ $field_name ][ $index ] ) ) { $now_num = $repeat_multiple_data[ $field_name ][ $index ]; } // The index is starting point to refer to the total of the previous number than me ($index) $_temp = array_slice( $repeat_multiple_data[ $field_name ], 0, $index ); $sum = array_sum( $_temp ); $start = $sum; if ( $now_num ) { $value = array_slice( $value, $start, $now_num ); } else { $value = array(); } } return $value; } /** * Getting the non multi-value field meta data. * * @param WP_Post|WP_User|WP_Term|stdClass $wp_object Object meta object. * @param Smart_Custom_Fields_Field_Base $field Field object. * @param int $index Index of value. * @return string */ public function get_single_data_field_value( $wp_object, $field, $index ) { $meta = new Smart_Custom_Fields_Meta( $wp_object ); $field_name = $field->get( 'name' ); if ( is_null( $index ) ) { return SCF::get_default_value( $field, true ); } if ( $meta->is_saved_the_key( $field_name ) ) { $value = $meta->get( $field_name ); if ( isset( $value[ $index ] ) ) { return $value[ $index ]; } return ''; } return SCF::get_default_value( $field, true ); } /** * Displaying tr element for table of custom fields. * * @param WP_Post|WP_User|WP_Term|stdClass $wp_object Object meta object. * @param bool $is_repeat If repeat, return true. * @param array $fields Fields. * @param int|null $index Field index. */ protected function display_tr( $wp_object, $is_repeat, $fields, $index = null ) { $btn_repeat = ''; if ( $is_repeat ) { $btn_repeat = sprintf( '', esc_attr( SCF_Config::PREFIX . 'icon-handle dashicons dashicons-menu' ) ); $btn_repeat .= ''; $btn_repeat .= ' '; } printf( '
    %s', esc_attr( SCF_Config::PREFIX . 'meta-box-table' ), is_null( $index ) ? 'style="display: none;"' : '', $btn_repeat // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ); foreach ( $fields as $field ) { $field_type = $field->get_attribute( 'type' ); // gets the field type for use in aditional CSS classes $layout = $field->get_attribute( 'layout' ); // get layout type $field_name = $field->get( 'name' ); $field_label = $field->get( 'label' ); if ( ! $field_label ) { $field_label = $field_name; } if ( $field->get_attribute( 'allow-multiple-data' ) ) { // When multi-value field $value = $this->get_multiple_data_field_value( $wp_object, $field, $index ); } else { // When non multi-value field $value = $this->get_single_data_field_value( $wp_object, $field, $index ); } $instruction = $field->get( 'instruction' ); if ( ! empty( $instruction ) ) { if ( apply_filters( SCF_Config::PREFIX . 'instruction-apply-html', false ) === true ) { $instruction_html = $instruction; } else { $instruction_html = esc_html( $instruction ); } $instruction = sprintf( '
    %s
    ', $instruction_html ); } printf( ' %2$s
    %3$s %4$s %5$s
    ', esc_attr( SCF_Config::PREFIX ), 'full-width' !== $layout ? '' . esc_html( $field_label ) . '' : '', $instruction, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $field->get_field( $index, $value ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped $field->get( 'notes' ) ? '

    ' . esc_html( $field->get( 'notes' ) ) . '

    ' : '', esc_attr( $field_type ), esc_attr( $layout ) ); } echo '
    '; } } controller/class.taxonomy.php000064400000005042146731356360012441 0ustar00get_groups(); ?>
    get_title() ); ?> display_meta_box( $term, $callback_args ); ?>
    save( filter_input_array( INPUT_POST ), $term ); } /** * Delete meta data. * * @param int $term_id Term ID. * @param int $term_taxonomy_id Term taxonomy ID. * @param string $taxonomy Taxonomy slug. * @param object $deleted_term Copy of the already-deleted term. */ public function delete( $term_id, $term_taxonomy_id, $taxonomy, $deleted_term ) { $meta = new Smart_Custom_Fields_Meta( $deleted_term ); $meta->delete(); } } controller/class.option.php000064400000004061146731356360012073 0ustar00
    get_groups(); ?>
    get_title() ); ?> display_meta_box( $option, $callback_args ); ?>

    save( filter_input_array( INPUT_POST ), $option ); } } controller/class.settings.php000064400000044063146731356360012431 0ustar00optgroups = array( 'basic-fields' => array( 'label' => esc_attr__( 'Basic fields', 'smart-custom-fields' ), 'options' => array(), ), 'select-fields' => array( 'label' => esc_attr__( 'Select fields', 'smart-custom-fields' ), 'options' => array(), ), 'content-fields' => array( 'label' => esc_attr__( 'Content fields', 'smart-custom-fields' ), 'options' => array(), ), 'other-fields' => array( 'label' => esc_attr__( 'Other fields', 'smart-custom-fields' ), 'options' => array(), ), ); } /** * Get Current Admin Color Scheme. * * @return object */ protected function admin_color_scheme() { global $_wp_admin_css_colors; $user_admin_color_scheme = get_user_option( 'admin_color' ); $colors_obj = $_wp_admin_css_colors[ $user_admin_color_scheme ]; return $colors_obj; } /** * Add Custom Inline CSS on Admin Dashboard. */ public function admin_inline_css() { $colors = $this->admin_color_scheme()->colors; ?> esc_html__( 'Same name exists!', 'smart-custom-fields' ), 'autocomplete_placeholder' => esc_html__( 'Type to search a post or page', 'smart-custom-fields' ), 'loading' => esc_html__( 'Loading...', 'smart-custom-fields' ), 'load_more' => esc_html__( 'Load more', 'smart-custom-fields' ), 'rest_api_url' => rest_url( SCF_Config::PREFIX . 'api/v2/search/posts' ), 'nonce' => wp_create_nonce( 'wp_rest' ), ) ); wp_enqueue_script( 'jquery-ui-sortable' ); do_action( SCF_Config::PREFIX . 'after-settings-enqueue-scripts' ); } /** * Adding meta boxes. */ public function add_meta_boxes() { add_meta_box( SCF_Config::PREFIX . 'meta-box', __( 'Custom Fields', 'smart-custom-fields' ), array( $this, 'display_meta_box' ), SCF_Config::NAME ); add_meta_box( SCF_Config::PREFIX . 'meta-box-condition-post', __( 'Display conditions ( Post )', 'smart-custom-fields' ), array( $this, 'display_meta_box_condition_post' ), SCF_Config::NAME, 'side' ); add_meta_box( SCF_Config::PREFIX . 'meta-box-condition-profile', __( 'Display conditions ( Profile )', 'smart-custom-fields' ), array( $this, 'display_meta_box_condition_profile' ), SCF_Config::NAME, 'side' ); add_meta_box( SCF_Config::PREFIX . 'meta-box-condition-taxonomy', __( 'Display conditions ( Taxonomy )', 'smart-custom-fields' ), array( $this, 'display_meta_box_condition_taxonomy' ), SCF_Config::NAME, 'side' ); add_meta_box( SCF_Config::PREFIX . 'meta-box-condition-options-page', __( 'Display conditions ( Options page )', 'smart-custom-fields' ), array( $this, 'display_meta_box_condition_options_page' ), SCF_Config::NAME, 'side' ); } /** * Displaying "hide" if $key isn't empty. * * @param string $key Key. */ private function add_hide_class( $key ) { if ( ! $key ) { echo 'hide'; } } /** * Displaying custom fields. */ public function display_meta_box() { $setting = SCF::add_setting( get_the_ID(), get_the_title() ); $setting->add_group_unshift(); $groups = $setting->get_groups(); ?>
    $group ) : ?> get_fields(); array_unshift( $fields, SCF::get_form_field_instance( 'text' ) ); ?>
    display_options( $group_key ); ?>
    $field ) : ?>
    get( 'name' ); $field_label = $field->get( 'label' ); if ( ! $field_label ) { $field_label = $field_name; if ( ! $field_label ) { $field_label = ' '; } } ?>
    [ ]
    display_options( $group_key, $field_key ); ?>
    *
    true, ), 'objects' ); unset( $post_types['attachment'] ); unset( $post_types['wp_block'] ); unset( $post_types[ SCF_Config::NAME ] ); $conditions = get_post_meta( get_the_ID(), SCF_Config::PREFIX . 'condition', true ); $post_type_field = ''; foreach ( $post_types as $post_type => $post_type_object ) { $current = is_array( $conditions ) && in_array( $post_type, $conditions, true ) ? $post_type : false; $post_type_field .= sprintf( '', esc_attr( SCF_Config::PREFIX . 'condition[]' ), esc_attr( $post_type ), checked( $current, $post_type, false ), esc_attr( $post_type_object->labels->singular_name ) ); } printf( // Translators: %1$s: Label, %2$s: Post type field '

    %1$s%2$s

    ', esc_html__( 'Post Types', 'smart-custom-fields' ), $post_type_field // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ); $condition_post_ids = get_post_meta( get_the_ID(), SCF_Config::PREFIX . 'condition-post-ids', true ); // get all posts saved $saved_posts = explode( ',', $condition_post_ids ); if ( $saved_posts ) { $saved = array(); foreach ( $saved_posts as $k => $post_id ) { if ( '' !== $post_id ) { $saved[ $k ]['id'] = $post_id; $saved[ $k ]['text'] = $post_id; } } } // create variable js with posting IDs to use in post search results printf( '', wp_json_encode( array_values( $saved ) ) ); // create div to use with jquery plugin "selectivity" // https://github.com/arendjr/selectivity printf( '

    %s

    ', esc_html__( 'Post or Page Ids', 'smart-custom-fields' ), esc_attr( SCF_Config::PREFIX . 'autocomplete-condition-post' ) ); // create input hidden with the IDS of saved posts printf( // Translators: %1$s: name, %2$s: value '', esc_attr( SCF_Config::PREFIX . 'condition-post-ids' ), esc_attr( $condition_post_ids ) ); } /** * Displaying the meta box to set the display conditions for profile edit page. */ public function display_meta_box_condition_profile() { $roles = get_editable_roles(); $conditions = get_post_meta( get_the_ID(), SCF_Config::PREFIX . 'roles', true ); $profile_field = ''; foreach ( $roles as $name => $role ) { $current = is_array( $conditions ) && in_array( $name, $conditions, true ) ? $name : false; $profile_field .= sprintf( '', esc_attr( SCF_Config::PREFIX . 'roles[]' ), esc_attr( $name ), checked( $current, $name, false ), // phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText esc_html__( $role['name'], 'smart-custom-fields' ) ); } printf( // Translators: %1$s: Label, %2$s: Roles field '

    %1$s%2$s

    ', esc_html__( 'Roles', 'smart-custom-fields' ), $profile_field // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ); } /** * Displaying the meta box to set the display conditions for term edit page. */ public function display_meta_box_condition_taxonomy() { $taxonomies = get_taxonomies( array( 'show_ui' => true, ), 'objects' ); $conditions = get_post_meta( get_the_ID(), SCF_Config::PREFIX . 'taxonomies', true ); $taxonomy_field = ''; foreach ( $taxonomies as $name => $taxonomy ) { $current = is_array( $conditions ) && in_array( $name, $conditions, true ) ? $name : false; $taxonomy_field .= sprintf( '', esc_attr( SCF_Config::PREFIX . 'taxonomies[]' ), esc_attr( $name ), checked( $current, $name, false ), // phpcs:ignore WordPress.WP.I18n.NonSingularStringLiteralText esc_html__( $taxonomy->label, 'smart-custom-fields' ) ); } printf( // Translators: %1$s: Label, %2$s: Taxonomy field '

    %1$s%2$s

    ', esc_html__( 'Taxonomies', 'smart-custom-fields' ), $taxonomy_field // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ); } /** * Displaying the meta box to set the display conditions for custom options page. */ public function display_meta_box_condition_options_page() { $optinos_pages = SCF::get_options_pages(); $conditions = get_post_meta( get_the_ID(), SCF_Config::PREFIX . 'options-pages', true ); $options_page_field = ''; foreach ( $optinos_pages as $name => $optinos_page ) { $current = is_array( $conditions ) && in_array( $name, $conditions, true ) ? $name : false; $options_page_field .= sprintf( '', esc_attr( SCF_Config::PREFIX . 'options-pages[]' ), esc_attr( $name ), checked( $current, $name, false ), esc_html( $optinos_page ) ); } printf( // Translators: %1$s: Label, %2$s: Options page field '

    %1$s%2$s

    ', esc_html__( 'Options pages', 'smart-custom-fields' ), $options_page_field // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ); } /** * Saving settings. * * @param int $post_id The post id. */ public function save_post( $post_id ) { if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return; } $posted_data = filter_input( INPUT_POST, SCF_Config::NAME, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); if ( ! $posted_data ) { return; } check_admin_referer( SCF_Config::NAME . '-settings', SCF_Config::PREFIX . 'settings-nonce' ); $data = array(); foreach ( $posted_data as $group_key => $group_value ) { // $group_key = 0 is hidden field so don't save if ( 0 === $group_key ) { continue; } if ( ! empty( $group_value['fields'] ) && count( $group_value['fields'] ) > 1 ) { $fields = array(); foreach ( $group_value['fields'] as $field_key => $field_value ) { // $field_key = 0 is hidden field so don't save if ( 0 === $field_key ) { continue; } if ( ! empty( $field_value['name'] ) ) { $fields[] = $field_value; } } if ( ! $fields ) { continue; } if ( ! empty( $group_value['repeat'] ) && 'true' === $group_value['repeat'] ) { $group_value['repeat'] = true; } else { $group_value['repeat'] = false; } // If "repeat" isn't true, empty name // If "repeat" is true and name is empty, assign index if ( ! isset( $group_value['repeat'] ) || true !== $group_value['repeat'] || empty( $group_value['group-name'] ) ) { $group_value['group-name'] = $group_key; } $group_value['fields'] = $fields; $data[] = $group_value; } } update_post_meta( $post_id, SCF_Config::PREFIX . 'setting', $data ); $poste_condition = filter_input( INPUT_POST, SCF_Config::PREFIX . 'condition', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); if ( ! $poste_condition ) { delete_post_meta( $post_id, SCF_Config::PREFIX . 'condition' ); } else { update_post_meta( $post_id, SCF_Config::PREFIX . 'condition', $poste_condition ); } $poste_condition_post_ids = filter_input( INPUT_POST, SCF_Config::PREFIX . 'condition-post-ids' ); if ( ! $poste_condition_post_ids ) { delete_post_meta( $post_id, SCF_Config::PREFIX . 'condition-post-ids' ); } else { update_post_meta( $post_id, SCF_Config::PREFIX . 'condition-post-ids', $poste_condition_post_ids ); } $poste_roles = filter_input( INPUT_POST, SCF_Config::PREFIX . 'roles', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); if ( ! $poste_roles ) { delete_post_meta( $post_id, SCF_Config::PREFIX . 'roles' ); } else { update_post_meta( $post_id, SCF_Config::PREFIX . 'roles', $poste_roles ); } $poste_taxonomies = filter_input( INPUT_POST, SCF_Config::PREFIX . 'taxonomies', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); if ( ! $poste_taxonomies ) { delete_post_meta( $post_id, SCF_Config::PREFIX . 'taxonomies' ); } else { update_post_meta( $post_id, SCF_Config::PREFIX . 'taxonomies', $poste_taxonomies ); } $poste_options_pages = filter_input( INPUT_POST, SCF_Config::PREFIX . 'options-pages', FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ); if ( ! $poste_options_pages ) { delete_post_meta( $post_id, SCF_Config::PREFIX . 'options-pages' ); } else { update_post_meta( $post_id, SCF_Config::PREFIX . 'options-pages', $poste_options_pages ); } } } controller/class.profile.php000064400000003724146731356360012230 0ustar00%s', esc_html__( 'Custom Fields', 'smart-custom-fields' ) ); $settings = SCF::get_settings( $user ); $callback_args = array(); foreach ( $settings as $setting ) { $callback_args['args'] = $setting->get_groups(); ?>
    get_title() ); ?> display_meta_box( $user, $callback_args ); ?>
    save( filter_input_array( INPUT_POST ), get_userdata( $user_id ) ); } } controller/class.editor.php000064400000002704146731356360012053 0ustar00get_id(), $setting->get_title(), array( $this, 'display_meta_box' ), $post_type, 'normal', 'default', $setting->get_groups() ); } } /** * Saving meta data from custom fields in post edit page. * * @param int $post_id Post id. */ public function save_post( $post_id ) { if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return; } if ( wp_is_post_autosave( $post_id ) || wp_is_post_revision( $post_id ) ) { return; } if ( ! filter_input( INPUT_POST, SCF_Config::NAME, FILTER_DEFAULT, FILTER_REQUIRE_ARRAY ) ) { return; } $this->save( filter_input_array( INPUT_POST ), get_post( $post_id ) ); } } queries/image.php000064400000003416146731442030010024 0ustar00model = $model; $this->mode = "generation"; // could be generation, edit, variation global $mwai_core; $this->localDownload = $mwai_core->get_option( 'image_local_download' ); $this->localDownloadExpiry = $mwai_core->get_option( 'image_expires' ); } #endregion #region Parameters public function set_resolution( string $resolution ) { $this->resolution = $resolution; } public function set_style( string $style ) { $this->style = $style; } /** * Set how the image will be treated locally, if it will be downloaded or not, etc. * @param string $localDownload The local download method.