- >
+
+
+
+ >
$pt ) : ?>
- >label; ?>
-
+ >label ); ?>
+
-
-
- >
- >
+
+
+
+ >
+ >
-
-
+
+
+
$params ) {
- if ( !is_array($params) || !empty($params['__delete__']) || empty($params['related_id']) ) {
+ if ( ! is_array( $params ) || ! empty( $params['__delete__'] ) || empty( $params['related_id'] ) ) {
continue;
}
- unset($params['__delete__']);
- $values[$key] = $params['related_id'];
+ unset( $params['__delete__'] );
+ $values[ $key ] = $params['related_id'];
}
- $values = array_values($values);
+ $values = array_values( $values );
+
return $values;
}
/**
- * update instance (settings) for current field
+ * Update instance (settings) for current field
+ *
+ * @param array $new_instance New instance.
+ * @param array $old_instance Old instance.
+ *
+ * @return array
*/
- public function update( $new_instance, $old_instance )
- {
- $instance = $old_instance;
- $instance['title'] = strip_tags($new_instance['title']);
- $instance['post_type'] = strip_tags($new_instance['post_type']);
- $instance['input_type'] = strip_tags($new_instance['input_type']);
- $instance['description'] = strip_tags($new_instance['description']);
+ public function update( $new_instance, $old_instance ) {
+ $instance = $old_instance;
+ $instance['title'] = strip_tags( $new_instance['title'] );
+ $instance['post_type'] = strip_tags( $new_instance['post_type'] );
+ $instance['input_type'] = strip_tags( $new_instance['input_type'] );
+ $instance['description'] = strip_tags( $new_instance['description'] );
+
return $instance;
}
/**
- * custom get_field functions to add one more deep level
+ * Custom get_field functions to add one more deep level
+ *
+ * @param mixed $field Field.
+ * @param mixed $number Number.
+ *
+ * @return mixed
*/
- protected function getFieldIdL2( $field, $number )
- {
- return $this->getFieldId($number . '-' . $field);
+ protected function get_field_id_l2( $field, $number ) {
+ return $this->get_field_id( $number . '-' . $field );
}
- protected function getFieldNameL2( $field, $number )
- {
- return $this->getFieldName($number . '][' . $field);
+ /**
+ * Custom get_field functions to add one more deep level
+ *
+ * @param mixed $field Field.
+ * @param mixed $number Number.
+ *
+ * @return mixed
+ */
+ protected function get_field_name_l2( $field, $number ) {
+ return $this->get_field_name( $number . '][' . $field );
}
/**
- * add custom scripts
+ * Add custom scripts
*/
- public function addJs()
- {
+ public function add_js() {
wp_register_script(
'jcf_related_content',
- plugins_url( '/related-content.js', __FILE__ ),
- array( 'jquery', 'jquery-ui-autocomplete', 'jquery-ui-sortable', 'jcf_edit_post' )
+ plugins_url( '/related-content.js', __FILE__ ),
+ array( 'jquery', 'jquery-ui-autocomplete', 'jquery-ui-sortable', 'jcf_edit_post' )
);
- wp_enqueue_script('jcf_related_content');
+ wp_enqueue_script( 'jcf_related_content' );
- // add text domain if not registered with another component
+ // add text domain if not registered with another component.
global $wp_scripts;
- if ( empty($wp_scripts->registered['jcf_fields_group']) && empty($wp_scripts->registered['jcf_uploadmedia']) ) {
- wp_localize_script('jcf_related_content', 'jcf_textdomain', jcf_get_language_strings());
+ if ( empty( $wp_scripts->registered['jcf_fields_group'] ) && empty( $wp_scripts->registered['jcf_uploadmedia'] ) ) {
+ wp_localize_script( 'jcf_related_content', 'jcf_textdomain', jcf_get_language_strings() );
}
}
- public function addCss()
- {
- wp_register_style('ui-autocomplete', plugins_url( '/assets/jquery-ui-1.8.14.autocomplete.css', __FILE__ ));
- wp_enqueue_style('ui-autocomplete');
+ /**
+ * Add custom styles
+ */
+ public function add_css() {
+ wp_register_style( 'ui-autocomplete', plugins_url( '/assets/jquery-ui-1.8.14.autocomplete.css', __FILE__ ) );
+ wp_enqueue_style( 'ui-autocomplete' );
- wp_register_style('jcf_related_content', plugins_url( '/related-content.css', __FILE__ ), array( 'jcf_edit_post' ) );
- wp_enqueue_style('jcf_related_content');
+ wp_register_style( 'jcf_related_content', plugins_url( '/related-content.css', __FILE__ ), array( 'jcf_edit_post' ) );
+ wp_enqueue_style( 'jcf_related_content' );
}
/**
- * print fields values from shortcode
+ * Print field values inside the shortcode
+ *
+ * @param array $args shortcode args.
+ *
+ * @return mixed
*/
- public function shortcodeValue( $args )
- {
- if ( empty($this->entry) )
+ public function shortcode_value( $args ) {
+ if ( empty( $this->entry ) ) {
return;
+ }
$html = '';
foreach ( $this->entry as $key => $entry ) {
- $post_link = get_permalink($entry);
- $post_title = get_the_title($entry);
- $html .= '' . esc_html($post_title) . ' ';
+ $post_link = get_permalink( $entry );
+ $post_title = get_the_title( $entry );
+ $html .= '' . esc_html( $post_title ) . ' ';
}
$html .= ' ';
@@ -272,45 +323,46 @@ public function shortcodeValue( $args )
/**
* Autocomplete ajax callback
*/
- public function ajaxAutocomplete() {
- if ( empty($_POST['term']) )
- die('');
+ public function ajax_autocomplete() {
+ if ( empty( $_POST['term'] ) ) {
+ die( '' );
+ }
- $post_type = $_POST['post_types'];
- $post_types = jcf_get_post_types('object');
+ $post_type = $_POST['post_types'];
+ $post_types = jcf_get_post_types( 'object' );
- if ( $post_type != 'any' ) {
+ if ( 'any' !== $post_type ) {
$post_type_where = " post_type = '" . $_POST['post_types'] . "' ";
- }
- else {
- // get all post types
- $post_type_where = "( post_type = '" . implode("' OR post_type = '", array_keys($post_types)) . "' )";
+ } else {
+ // get all post types.
+ $post_type_where = "( post_type = '" . implode( "' OR post_type = '", array_keys( $post_types ) ) . "' )";
}
global $wpdb;
- $query = "SELECT ID, post_title, post_status, post_type
+ $query = "SELECT ID, post_title, post_status, post_type
FROM $wpdb->posts
WHERE $post_type_where AND (post_status = 'publish' OR post_status = 'draft') AND post_title LIKE '%" . $_POST['term'] . "%'
ORDER BY post_title";
- $posts = $wpdb->get_results($query);
+ $posts = $wpdb->get_results( $query );
$response = array();
foreach ( $posts as $p ) {
- $draft = ( $p->post_status == 'draft' ) ? ' (DRAFT)' : '';
- $type_label = ( $_POST['post_types'] != 'any' ) ? '' : ' / ' . $post_types[$p->post_type]->labels->singular_name;
+ $draft = ( 'draft' === $p->post_status ) ? ' (DRAFT)' : '';
+ $type_label = ( 'any' !== $_POST['post_types'] ) ? '' : ' / ' . $post_types[ $p->post_type ]->labels->singular_name;
$response[] = array(
- 'id' => $p->ID,
- 'label' => $p->post_title . $draft . $type_label,
- 'value' => $p->post_title . $draft . $type_label,
- 'type' => $p->post_type,
- 'status' => $p->post_status
+ 'id' => $p->ID,
+ 'label' => $p->post_title . $draft . $type_label,
+ 'value' => $p->post_title . $draft . $type_label,
+ 'type' => $p->post_type,
+ 'status' => $p->post_status,
);
}
- $result = json_encode($response);
- header("Content-Type: application/json; charset=" . get_bloginfo('charset'));
+ $result = json_encode( $response );
+ header( 'Content-Type: application/json; charset=' . get_bloginfo( 'charset' ) );
echo $result;
exit();
}
}
+
?>
\ No newline at end of file
diff --git a/components/relatedcontent/related-content.js b/components/relatedcontent/related-content.js
index 38d9834..ba906a6 100755
--- a/components/relatedcontent/related-content.js
+++ b/components/relatedcontent/related-content.js
@@ -68,7 +68,7 @@ function jcf_relatedcontent_init() {
jcf_relatedcontent_init_sortable(container);
return false;
- })
+ });
function jcf_attach_autocomplete_event( input ) {
var post_types = jQuery(input).attr('alt');
diff --git a/components/select/JustField_Select.php b/components/select/JustField_Select.php
index 39a7387..ca94fb1 100644
--- a/components/select/JustField_Select.php
+++ b/components/select/JustField_Select.php
@@ -10,110 +10,145 @@
* @package default
* @author Alexander Prokopenko
*/
-class JustField_Select extends core\JustField
-{
+class JustField_Select extends core\JustField {
- public function __construct()
- {
+ /**
+ * Class constructor
+ **/
+ public function __construct() {
$field_ops = array( 'classname' => 'field_select' );
- parent::__construct('select', __('Select', \JustCustomFields::TEXTDOMAIN), $field_ops);
+ parent::__construct( 'select', __( 'Select', 'jcf' ), $field_ops );
}
/**
- * draw field on post edit form
- * you can use $this->instance, $this->entry
+ * Draw field on post edit form
+ * you can use $this->instance, $this->entry
*/
- public function field()
- {
- $values = $this->parsedSelectOptions($this->instance);
+ public function field() {
+ $values = $this->parsedSelectOptions( $this->instance );
?>
-
- fieldOptions['before_widget']; ?>
- fieldOptions['before_title'] . esc_html($this->instance['title']) . $this->fieldOptions['after_title']; ?>
-
-
- instance['empty_option'])) : ?>
- instance['empty_option'], $this->entry, false); ?>>instance['empty_option']); ?>
-
- $val ) : ?>
- entry, false); ?>>
-
-
-
- instance['description']) ) : ?>
-
instance['description']); ?>
+
+ field_options['before_widget']; ?>
+ field_options['before_title'] . esc_html( $this->instance['title'] ) . $this->field_options['after_title']; ?>
+
+
+ instance['empty_option'] ) ) : ?>
+ instance['empty_option'], $this->entry, false ); ?>>instance['empty_option'] ); ?>
+
+ $val ) : ?>
+ entry, false ); ?>>
+
+
+
+ instance['description'] ) ) : ?>
+
instance['description'] ); ?>
- fieldOptions['after_widget']; ?>
+ field_options['after_widget']; ?>
instance, array( 'title' => '', 'description' => '', 'options' => '', 'empty_option' => '' ));
- $title = esc_attr($instance['title']);
- $options = esc_attr($instance['options']);
- $description = esc_html($instance['description']);
- $empty_option = esc_attr($instance['empty_option']);
+ public function form() {
+ // Defaults.
+ $instance = wp_parse_args( (array) $this->instance, array(
+ 'title' => '',
+ 'description' => '',
+ 'options' => '',
+ 'empty_option' => '',
+ ) );
+ $title = esc_attr( $instance['title'] );
+ $options = esc_attr( $instance['options'] );
+ $description = esc_html( $instance['description'] );
+ $empty_option = esc_attr( $instance['empty_option'] );
?>
-
-
-
- label1|id1 label2|id2 label3', \JustCustomFields::TEXTDOMAIN); ?>
-
-
-
+
+
+
+
+
+
+
+
+ label1|id1 label2|id2 label3', 'jcf' ); ?>
+
+
+
+
+
+
+
+
+
parsedSelectOptions($this->instance);
- $options = array_flip($options);
- $value = $this->entry;
-
- if ( isset($options[$this->entry]) ) {
- $value = $options[$this->entry];
+ public function shortcode_value( $args ) {
+ $options = $this->parsedSelectOptions( $this->instance );
+ $options = array_flip( $options );
+ $value = $this->entry;
+
+ if ( isset( $options[ $this->entry ] ) ) {
+ $value = $options[ $this->entry ];
}
- return $args['before_value'] . esc_html($value) . $args['after_value'];
+
+ return $args['before_value'] . esc_html( $value ) . $args['after_value'];
}
}
diff --git a/components/selectmultiple/JustField_SelectMultiple.php b/components/selectmultiple/JustField_SelectMultiple.php
index 17212f3..8148ed3 100644
--- a/components/selectmultiple/JustField_SelectMultiple.php
+++ b/components/selectmultiple/JustField_SelectMultiple.php
@@ -10,104 +10,133 @@
* @package default
* @author Alexander Prokopenko
*/
-class JustField_SelectMultiple extends core\JustField
-{
+class JustField_SelectMultiple extends core\JustField {
- public function __construct()
- {
+ /**
+ * Class constructor
+ **/
+ public function __construct() {
$field_ops = array( 'classname' => 'field_selectmultiple' );
- parent::__construct('selectmultiple', __('Select Multiple', \JustCustomFields::TEXTDOMAIN), $field_ops);
+ parent::__construct( 'selectmultiple', __( 'Select Multiple', 'jcf' ), $field_ops );
}
/**
- * draw field on post edit form
- * you can use $this->instance, $this->entry
+ * Draw field on post edit form
+ * you can use $this->instance, $this->entry
*/
- public function field()
- {
- if ( !is_array($this->entry) )
+ public function field() {
+ if ( ! is_array( $this->entry ) ) {
$this->entry = array();
- // prepare options array
- $values = $this->parsedSelectOptions($this->instance);
+ }
+ // prepare options array.
+ $values = $this->parsedSelectOptions( $this->instance );
?>
-
- fieldOptions['before_widget']; ?>
- fieldOptions['before_title'] . esc_html($this->instance['title']) . $this->fieldOptions['after_title']; ?>
-
-
- $val ): ?>
- entry), false); ?>>
+
+ field_options['before_widget']; ?>
+ field_options['before_title'] . esc_html( $this->instance['title'] ) . $this->field_options['after_title']; ?>
+
+
+ $val ) : ?>
+ entry ), false ); ?>>
-
-
- instance['description'] != '' ) : ?>
-
instance['description']); ?>
-
- fieldOptions['after_widget']; ?>
+
+
+ instance['description'] ) : ?>
+ instance['description'] ); ?>
+
+ field_options['after_widget']; ?>
instance, array( 'title' => '', 'description' => '', 'settings' => '' ));
-
- $title = esc_attr($instance['title']);
- $options = esc_attr($instance['options']);
- $description = esc_html($instance['description']);
+ public function form() {
+ // Defaults.
+ $instance = wp_parse_args( (array) $this->instance, array(
+ 'title' => '',
+ 'description' => '',
+ 'settings' => '',
+ ) );
+
+ $title = esc_attr( $instance['title'] );
+ $options = esc_attr( $instance['options'] );
+ $description = esc_html( $instance['description'] );
?>
-
-
-
-
- label1|id1 label2|id2 label3', \JustCustomFields::TEXTDOMAIN); ?>
-
+
+
+
+
+
+
+
+
+
+ label1|id1 label2|id2 label3', 'jcf' ); ?>
+
+
+
+
parsedSelectOptions($this->instance);
- $options = array_flip($options);
+ public function shortcode_value( $args ) {
+ $options = $this->parsedSelectOptions( $this->instance );
+ $options = array_flip( $options );
- if ( empty($this->entry) )
+ if ( empty( $this->entry ) ) {
return '';
+ }
$html = '
';
foreach ( $this->entry as $value ) {
- $key = preg_replace('/\s+/', '-', $value);
- $key = preg_replace('/[^0-9a-z\-\_]/i', '', $key);
- if ( isset($options[$value]) ) {
- $value = $options[$value];
+ $key = preg_replace( '/\s+/', '-', $value );
+ $key = preg_replace( '/[^0-9a-z\-\_]/i', '', $key );
+ if ( isset( $options[ $value ] ) ) {
+ $value = $options[ $value ];
}
- $key = esc_attr($key);
- $value = esc_html($value);
- $html .= "$value \r\n";
+ $key = esc_attr( $key );
+ $value = esc_html( $value );
+ $html .= "$value \r\n";
}
$html .= ' ';
@@ -143,4 +176,5 @@ public function shortcodeValue( $args )
}
}
+
?>
\ No newline at end of file
diff --git a/components/selectmultiple/views/field.tpl.php b/components/selectmultiple/views/field.tpl.php
index d78562b..41a2494 100755
--- a/components/selectmultiple/views/field.tpl.php
+++ b/components/selectmultiple/views/field.tpl.php
@@ -5,7 +5,7 @@
-
+
$val ): ?>
entry), false); ?>>
diff --git a/components/selectmultiple/views/form.tpl.php b/components/selectmultiple/views/form.tpl.php
index 49297fe..7247600 100755
--- a/components/selectmultiple/views/form.tpl.php
+++ b/components/selectmultiple/views/form.tpl.php
@@ -6,9 +6,9 @@
$settings = esc_attr($instance['settings']);
$description = esc_html($instance['description']);
?>
-
+
-
-
- label1|id1 label2|id2 label3', \JustCustomFields::TEXTDOMAIN); ?>
-
+
+
+ label1|id1 label2|id2 label3', 'jcf'); ?>
+
diff --git a/components/simplemedia/JustField_SimpleMedia.php b/components/simplemedia/JustField_SimpleMedia.php
index 0e059e0..1390594 100644
--- a/components/simplemedia/JustField_SimpleMedia.php
+++ b/components/simplemedia/JustField_SimpleMedia.php
@@ -5,183 +5,242 @@
use jcf\core;
/**
- * Simple Upload media field
+ * Simple Upload media field
*/
-class JustField_SimpleMedia extends core\JustField
-{
- public static $compatibility = "4.0+";
+class JustField_SimpleMedia extends core\JustField {
- public function __construct()
- {
+ /**
+ * Capability
+ *
+ * @var $compatibility
+ */
+ public static $compatibility = '4.0+';
+
+ /**
+ * Class constructor
+ **/
+ public function __construct() {
$field_ops = array( 'classname' => 'field_simplemedia' );
- parent::__construct('simplemedia', __('Simple Media', \JustCustomFields::TEXTDOMAIN), $field_ops);
+ parent::__construct( 'simplemedia', __( 'Simple Media', 'jcf' ), $field_ops );
}
/**
- * draw field on post edit form
- * you can use $this->instance, $this->entry
+ * Draw field on post edit form
+ * you can use $this->instance, $this->entry
*/
- public function field()
- {
- $noimage = $image = jcf_plugin_url('components/simplemedia/assets/jcf-noimage100x77.jpg');
+ public function field() {
+ $noimage = $image = jcf_plugin_url( 'components/simplemedia/assets/jcf-noimage100x77.jpg' );
$delete_class = ' jcf-hide';
- $upload_type = $this->instance['type'];
- $upload_text = ($upload_type == 'image') ? __('Select image', \JustCustomFields::TEXTDOMAIN) : __('Select file', \JustCustomFields::TEXTDOMAIN);
- $value = $link = '#';
+ $upload_type = $this->instance['type'];
+ $upload_text = ( 'image' === $upload_type ) ? __( 'Select image', 'jcf' ) : __( 'Select file', 'jcf' );
+ $value = $link = '#';
- if ( empty($this->entry) )
+ if ( empty( $this->entry ) ) {
$this->entry = 0;
+ }
?>
-
- fieldOptions['before_widget']; ?>
- fieldOptions['before_title'] . esc_html($this->instance['title']) . $this->fieldOptions['after_title']; ?>
-
- entry) ) {
- $value = esc_attr($this->entry);
- $link = wp_get_attachment_url($this->entry);
- $upload_text = ($upload_type == 'image') ? __('Update image', \JustCustomFields::TEXTDOMAIN) : __('Update file', \JustCustomFields::TEXTDOMAIN);
- $delete_class = '';
- }
- ?>
-
-
-
+
+ field_options['before_widget']; ?>
+ field_options['before_title'] . esc_html( $this->instance['title'] ) . $this->field_options['after_title']; ?>
+
+ entry ) ) {
+ $value = esc_attr( $this->entry );
+ $link = wp_get_attachment_url( $this->entry );
+ $upload_text = ( 'image' === $upload_type ) ? __( 'Update image', 'jcf' ) : __( 'Update file', 'jcf' );
+ $delete_class = '';
+ }
+ ?>
+
+
- instance['description'] != '' ) : ?>
-
instance['description']); ?>
-
- fieldOptions['after_widget']; ?>
+ instance['description'] ) : ?>
+
instance['description'] ); ?>
+
+ field_options['after_widget']; ?>
instance, array( 'title' => '', 'type' => 'file', 'autoresize' => '',
- 'description' => '' ));
- $instance['type'] = (isset($this->instance['type'])) ? $this->instance['type'] : 'file';
- $title = esc_attr($instance['title']);
- $type = $instance['type'];
- $description = esc_html($instance['description']);
+ public function form() {
+ // Defaults.
+ $instance = wp_parse_args( (array) $this->instance, array(
+ 'title' => '',
+ 'type' => 'file',
+ 'autoresize' => '',
+ 'description' => '',
+ ) );
+ $instance['type'] = ( isset( $this->instance['type'] ) ) ? $this->instance['type'] : 'file';
+ $title = esc_attr( $instance['title'] );
+ $type = $instance['type'];
+ $description = esc_html( $instance['description'] );
?>
-
-
-
-
- >
- >
+
+
+
+
+
+
+ >
+ >
-
+
+
+
( $post_ID ? $post_ID : null ) ));
- wp_enqueue_script("jcf-simpleupload-modal", jcf_plugin_url('components/simplemedia/assets/simplemedia-modal.js'), array( 'jquery', 'media-models', 'jcf_edit_post' ));
-
- // add text domain if not registered with another component
+ }
+ wp_enqueue_media( array( 'post' => ( $post_id ? $post_id : null ) ) );
+ wp_enqueue_script( 'jcf-simpleupload-modal', jcf_plugin_url( 'components/simplemedia/assets/simplemedia-modal.js' ), array(
+ 'jquery',
+ 'media-models',
+ 'jcf_edit_post',
+ ) );
+
+ // add text domain if not registered with another component.
global $wp_scripts;
- if ( empty($wp_scripts->registered['jcf_fields_group']) && empty($wp_scripts->registered['jcf_related_content']) ) {
- wp_localize_script('jcf_simplemedia', 'jcf_textdomain', jcf_get_language_strings());
+ if ( empty( $wp_scripts->registered['jcf_fields_group'] ) && empty( $wp_scripts->registered['jcf_related_content'] ) ) {
+ wp_localize_script( 'jcf_simplemedia', 'jcf_textdomain', jcf_get_language_strings() );
}
}
-
- public function addCss()
- {
- wp_register_style('jcf_simplemedia', jcf_plugin_url('components/simplemedia/assets/simplemedia.css'), array( 'thickbox', 'jcf_edit_post' ));
- wp_enqueue_style('jcf_simplemedia');
+ /**
+ * Add custom styles
+ */
+ public function add_css() {
+ wp_register_style( 'jcf_simplemedia', jcf_plugin_url( 'components/simplemedia/assets/simplemedia.css' ), array(
+ 'thickbox',
+ 'jcf_edit_post',
+ ) );
+ wp_enqueue_style( 'jcf_simplemedia' );
}
/**
- * print field values inside the shortcode
+ * Print field values inside the shortcode
*
- * @params array $args shortcode args
+ * @param array $args shortcode args.
+ *
+ * @return mixed
*/
- public function shortcodeValue( $args )
- {
- if ( empty($this->entry) ) return '';
+ public function shortcode_value( $args ) {
+ if ( empty( $this->entry ) ) {
+ return '';
+ }
- $size = isset($args['size'])? $args['size'] : 'thumbnail';
- $value = wp_get_attachment_image($this->entry, $size);
+ $size = isset( $args['size'] ) ? $args['size'] : 'thumbnail';
+ $value = wp_get_attachment_image( $this->entry, $size );
return $args['before_value'] . $value . $args['after_value'];
}
}
+
?>
diff --git a/components/simplemedia/assets/simplemedia-modal.js b/components/simplemedia/assets/simplemedia-modal.js
index dcce0e3..dff8835 100755
--- a/components/simplemedia/assets/simplemedia-modal.js
+++ b/components/simplemedia/assets/simplemedia-modal.js
@@ -85,7 +85,7 @@ window.JcfSimpleMedia = {
row.find('p:first').html(html).removeClass('jcf-hide').show();
row.find('a.jcf_simple_delete').removeClass('jcf-hide').show();
}
-}
+};
jQuery(document).ready(function() {
if ( jQuery('body').hasClass('edit-tags-php') ) {
@@ -108,7 +108,7 @@ jQuery(document).ready(function() {
// rename upload control
row.find('#simplemedia-' + value_id).text( jcf_textdomain.select_image );
// reset image
- row.find('.jcf-simple-image a').attr('href', '#')
+ row.find('.jcf-simple-image a').attr('href', '#');
var img = row.find('.jcf-simple-image img');
img.attr('src', img.data('noimage'));
@@ -124,4 +124,4 @@ jQuery(document).ready(function() {
row.find('#simplemedia-' + value_id).show();
return false;
});
-})
\ No newline at end of file
+});
\ No newline at end of file
diff --git a/components/table/JustField_Table.php b/components/table/JustField_Table.php
index 5c81b2f..beb225c 100644
--- a/components/table/JustField_Table.php
+++ b/components/table/JustField_Table.php
@@ -10,61 +10,62 @@
* @package default
* @author Sergey Samoylov
*/
-class JustField_Table extends core\JustField
-{
+class JustField_Table extends core\JustField {
- public function __construct()
- {
+ /**
+ * JustField_Table constructor.
+ */
+ public function __construct() {
$field_ops = array( 'classname' => 'field_table' );
- parent::__construct('table', __('Table', \JustCustomFields::TEXTDOMAIN), $field_ops);
+ parent::__construct( 'table', __( 'Table', 'jcf' ), $field_ops );
}
/**
- * draw field on post edit form
- * you can use $this->instance, $this->entry
+ * Draw field on post edit form
+ * you can use $this->instance, $this->entry
*/
- public function field()
- {
- if ( empty($this->entry) )
+ public function field() {
+ if ( empty( $this->entry ) ) {
$this->entry = array();
+ }
- // add null element for etalon copy
+ // add null element for etalon copy.
$entries = (array) $this->entry;
- // get fields
- $columns = $this->parseColumnsOptions();
+ // get fields.
+ $columns = $this->parse_columns_options();
- if ( !empty($columns) ) {
- // generate th headings and row to be cloned
- $count_cols = count($columns);
+ if ( ! empty( $columns ) ) {
+ // generate th headings and row to be cloned.
+ $count_cols = count( $columns );
$table_headers = '
Options ';
- $clone_row = '
+ $clone_row = '
';
- foreach ($columns as $col_name => $col_title) {
+ foreach ( $columns as $col_name => $col_title ) {
$table_headers .= '
' . $col_title . ' ';
- $clone_row .= '
';
+ $clone_row .= '
';
}
- // generate rows html
+ // generate rows html.
$rows = '';
- $rows .= '
'
- . __('No data yet.', \JustCustomFields::TEXTDOMAIN)
- . ' ';
+ $rows .= '
'
+ . __( 'No data yet.', 'jcf' )
+ . ' ';
- foreach ($entries as $key => $entry) {
+ foreach ( $entries as $key => $entry ) {
$rows .= '
';
- foreach ($columns as $col_name => $col_title) {
- $rows .= '
+ foreach ( $columns as $col_name => $col_title ) {
+ $rows .= '
';
}
@@ -72,169 +73,222 @@ public function field()
}
}
?>
-
- fieldOptions['before_widget']; ?>
- fieldOptions['before_title'] . esc_html($this->instance['title']) . $this->fieldOptions['after_title']; ?>
-
-
-
-
-
-
-
- instance['description'] != '' ): ?>
-
instance['description']); ?>
-
- fieldOptions['after_widget']; ?>
+
+ field_options['before_widget']; ?>
+ field_options['before_title'] . esc_html( $this->instance['title'] ) . $this->field_options['after_title']; ?>
+
+
+
+
+
+
+
+ instance['description'] ) : ?>
+
instance['description'] ); ?>
+
+ field_options['after_widget']; ?>
instance, array( 'title' => '', 'columns' => '', 'description' => '' ));
-
- $title = esc_attr($instance['title']);
- $columns = esc_html($instance['columns']);
- $description = esc_html($instance['description']);
+ public function form() {
+ // Defaults.
+ $instance = wp_parse_args( (array) $this->instance, array(
+ 'title' => '',
+ 'columns' => '',
+ 'description' => '',
+ ) );
+
+ $title = esc_attr( $instance['title'] );
+ $columns = $instance['columns'];
+ $description = esc_html( $instance['description'] );
?>
-
-
-
-
- Example: username|User name', \JustCustomFields::TEXTDOMAIN); ?>
-
-
+
+
+
+
+
+
+
+
+ Example: username|User name', 'jcf' ); ?>
+
+
+
+
$params ) {
- if ( !is_array($params) || !empty($params['__delete__']) ) {
+ if ( ! is_array( $params ) || ! empty( $params['__delete__'] ) ) {
continue;
}
- unset($params['__delete__']);
- $values[$key] = $params;
+ unset( $params['__delete__'] );
+ $values[ $key ] = $params;
}
- $values = array_values($values);
+ $values = array_values( $values );
+
return $values;
}
/**
- * update instance (settings) for current field
+ * Update instance (settings) for current field
+ *
+ * @param array $new_instance New instance.
+ * @param array $old_instance Old instance.
+ *
+ * @return array
*/
- public function update( $new_instance, $old_instance )
- {
- $instance = $old_instance;
- $instance['title'] = strip_tags($new_instance['title']);
- $instance['columns'] = strip_tags($new_instance['columns']);
- $instance['description'] = strip_tags($new_instance['description']);
+ public function update( $new_instance, $old_instance ) {
+ $instance = $old_instance;
+ $instance['title'] = strip_tags( $new_instance['title'] );
+ $instance['columns'] = strip_tags( $new_instance['columns'] );
+ $instance['description'] = strip_tags( $new_instance['description'] );
+
return $instance;
}
/**
- * custom get_field functions to add one more deep level
+ * Custom get_field functions to add one more deep level
+ *
+ * @param mixed $field Field.
+ * @param mixed $number Number.
+ *
+ * @return mixed
*/
- protected function getFieldIdL2( $field, $number )
- {
- return $this->getFieldId($number . '-' . $field);
+ protected function get_field_id_l2( $field, $number ) {
+ return $this->get_field_id( $number . '-' . $field );
}
- protected function getFieldNameL2( $field, $number )
- {
- return $this->getFieldName($number . '][' . $field);
+ /**
+ * Custom get_field functions to add one more deep level
+ *
+ * @param mixed $field Field.
+ * @param mixed $number Number.
+ *
+ * @return mixed
+ */
+ protected function get_field_name_l2( $field, $number ) {
+ return $this->get_field_name( $number . '][' . $field );
}
- public function addJs()
- {
+
+ /**
+ * Add custom scripts
+ */
+ public function add_js() {
global $wp_version;
- wp_register_script('jcf_table', jcf_plugin_url('components/table/table.js'), array( 'jquery', 'jquery-ui-sortable', 'jcf_edit_post' ));
- wp_enqueue_script('jcf_table');
+ wp_register_script( 'jcf_table', jcf_plugin_url( 'components/table/table.js' ), array(
+ 'jquery',
+ 'jquery-ui-sortable',
+ 'jcf_edit_post',
+ ) );
+ wp_enqueue_script( 'jcf_table' );
- // add text domain if not registered with another component
+ // add text domain if not registered with another component.
global $wp_scripts;
- wp_localize_script('jcf_table', 'jcf_textdomain', jcf_get_language_strings());
+ wp_localize_script( 'jcf_table', 'jcf_textdomain', jcf_get_language_strings() );
}
- public function addCss()
- {
- wp_register_style('jcf_table', jcf_plugin_url('components/table/table.css'), array( 'jcf_edit_post' ));
- wp_enqueue_style('jcf_table');
+ /**
+ * Add custom styles
+ */
+ public function add_css() {
+ wp_register_style( 'jcf_table', jcf_plugin_url( 'components/table/table.css' ), array( 'jcf_edit_post' ) );
+ wp_enqueue_style( 'jcf_table' );
}
/**
- * parse columns from settings
+ * Parse columns from settings
+ *
* @return array
*/
- protected function parseColumnsOptions()
- {
- $columns = array();
- $_columns = explode("\n", $this->instance['columns']);
+ protected function parse_columns_options() {
+ $columns = array();
+ $_columns = explode( "\n", $this->instance['columns'] );
foreach ( $_columns as $line ) {
- $line = trim($line);
- if ( strpos($line, '|') !== FALSE ) {
- $col_name = explode('|', $line);
- $columns[$col_name[0]] = $col_name[1];
- }
- elseif ( !empty($line) ) {
- $columns[$line] = $line;
+ $line = trim( $line );
+ if ( strpos( $line, '|' ) !== false ) {
+ $col_name = explode( '|', $line );
+ $columns[ $col_name[0] ] = $col_name[1];
+ } elseif ( ! empty( $line ) ) {
+ $columns[ $line ] = $line;
}
}
+
return $columns;
}
/**
- * print fields values from shortcode
+ * Print field values inside the shortcode
+ *
+ * @param array $args shortcode args.
+ *
+ * @return mixed
*/
- public function shortcodeValue( $args )
- {
- $columns = $this->parseColumnsOptions();
- if ( empty($columns) || empty($this->entry) )
+ public function shortcode_value( $args ) {
+ $columns = $this->parse_columns_options();
+ if ( empty( $columns ) || empty( $this->entry ) ) {
return '';
+ }
- $count_cols = count($columns);
+ $count_cols = count( $columns );
$thead_columns = '';
- $html = $rows = '';
+ $html = $rows = '';
foreach ( $this->entry as $key => $entry ) {
$rows .= '
';
foreach ( $columns as $col_name => $col_title ) {
- if ( $key == 0 ) {
- $thead_columns .= '' . esc_html($col_title) . ' ';
+ if ( 0 === $key ) {
+ $thead_columns .= '' . esc_html( $col_title ) . ' ';
}
- $rows .= '' . esc_html($entry[$col_name]) . ' ';
+ $rows .= '' . esc_html( $entry[ $col_name ] ) . ' ';
}
$rows .= ' ';
}
@@ -242,6 +296,7 @@ public function shortcodeValue( $args )
$html .= '
' . $thead_columns . ' ';
$html .= $rows;
$html .= '';
+
return $args['before_value'] . $html . $args['after_value'];
}
diff --git a/components/table/table.js b/components/table/table.js
index 14422b3..98c5b95 100755
--- a/components/table/table.js
+++ b/components/table/table.js
@@ -18,7 +18,7 @@ jQuery(document).ready(function() {
table.find('tr.no-rows').show();
}
jQuery(this).parent().parent().remove();
- })
+ });
jQuery('table.sortable').each(function() {
jQuery(this).find('tbody').sortable({containment: jQuery(this), scroll: false, items: 'tr[class!=table-header]'});
diff --git a/components/textarea/JustField_Textarea.php b/components/textarea/JustField_Textarea.php
index 91cb4ac..b8b9f38 100644
--- a/components/textarea/JustField_Textarea.php
+++ b/components/textarea/JustField_Textarea.php
@@ -10,119 +10,143 @@
* @package default
* @author Alexander Prokopenko
*/
-class JustField_Textarea extends core\JustField
-{
+class JustField_Textarea extends core\JustField {
- public function __construct()
- {
+ /**
+ * Class constructor
+ **/
+ public function __construct() {
$field_ops = array( 'classname' => 'field_textarea' );
- parent::__construct('textarea', __('Textarea', \JustCustomFields::TEXTDOMAIN), $field_ops);
+ parent::__construct( 'textarea', __( 'Textarea', 'jcf' ), $field_ops );
}
/**
- * draw field on post edit form
- * you can use $this->instance, $this->entry
+ * Draw field on post edit form
+ * you can use $this->instance, $this->entry
*/
- public function field()
- {
+ public function field() {
?>
-
- fieldOptions['before_widget']; ?>
- fieldOptions['before_title'] . esc_html($this->instance['title']) . $this->fieldOptions['after_title']; ?>
- instance['editor']) ) : // check editor
-
- ob_start();
- /**
- * @todo have bug with switching editor/text after ajax field loading, now disabled this functionality
- * @author Kirill Samojlenko
- */
- wp_editor($this->entry, $this->getFieldId('val'), array(
- 'textarea_name' => $this->getFieldName('val'),
- 'textarea_rows' => 5,
- 'media_buttons' => true,
- 'wpautop' => true,
- 'quicktags' => false,
- 'tinymce' => array(
- 'theme_advanced_buttons1' => 'bold,italic,strikethrough,|,bullist,numlist,blockquote,|,justifyleft,justifycenter,justifyright,|,link,unlink,|,spellchecker,fullscreen,wp_adv',
- ),
- ));
- echo ob_get_clean();
-
- if ( defined('DOING_AJAX') && DOING_AJAX ) :
- ?>
-
-
-
- isTaxonomyField() ) : ?>
-
+
+
+ is_taxonomy_field() ) : ?>
+
-
-
-
- entry); ?>
-
-
-
- instance['description']) ) : ?>
-
instance['description']); ?>
-
- fieldOptions['after_widget']; ?>
+ });
+
+
+
+
+ entry ); ?>
+
+
+
+ instance['description'] ) ) : ?>
+
instance['description'] ); ?>
+
+ field_options['after_widget']; ?>
instance, array( 'title' => '', 'description' => '' ));
- $title = esc_attr($instance['title']);
- $description = esc_html($instance['description']);
- $checked = !empty($instance['editor']) ? ' checked="checked" ' : '';
+ public function form() {
+ // Defaults.
+ $instance = wp_parse_args( (array) $this->instance, array( 'title' => '', 'description' => '' ) );
+ $title = esc_attr( $instance['title'] );
+ $description = esc_html( $instance['description'] );
+ $checked = ! empty( $instance['editor'] ) ? ' checked="checked" ' : '';
?>
-
-
/>
-
+
+
+
+
+
+ />
+
+
+
+
instance['editor'] ) {
- $values = wpautop($values);
+ $values = wpautop( $values );
}
+
return $values;
}
/**
- * update instance (settings) for current field
+ * Update instance (settings) for current field
+ *
+ * @param array $new_instance New instance.
+ * @param array $old_instance Old instance.
+ *
+ * @return array
*/
- public function update( $new_instance, $old_instance )
- {
- $instance = $old_instance;
- $instance['title'] = strip_tags($new_instance['title']);
- $instance['editor'] = (int) @$new_instance['editor'];
- $instance['description'] = strip_tags($new_instance['description']);
+ public function update( $new_instance, $old_instance ) {
+ $instance = $old_instance;
+ $instance['title'] = strip_tags( $new_instance['title'] );
+ $instance['editor'] = (int) @$new_instance['editor'];
+ $instance['description'] = strip_tags( $new_instance['description'] );
+
return $instance;
}
}
+
?>
\ No newline at end of file
diff --git a/controllers/AdminController.php b/controllers/AdminController.php
index 8a17a5a..a13a70f 100644
--- a/controllers/AdminController.php
+++ b/controllers/AdminController.php
@@ -5,108 +5,104 @@
use jcf\models;
use jcf\core;
-class AdminController extends core\Controller
-{
+/**
+ * Admin controller
+ */
+class AdminController extends core\Controller {
/**
* Init all wp-actions
*/
- public function __construct()
- {
+ public function __construct() {
parent::__construct();
- if ( ! defined('JCF_MIGRATE_MODE') ) {
- add_action('admin_menu', array( $this, 'adminMenu' ));
+ if ( ! defined( 'JCF_MIGRATE_MODE' ) ) {
+ add_action( 'admin_menu', array( $this, 'admin_menu' ) );
}
- if ( isset($_GET['page']) && strpos($_GET['page'], 'jcf_') !== FALSE ) {
- add_action('admin_print_scripts', array( $this, 'addScripts' ));
- add_action('admin_print_styles', array( $this, 'addStyles' ));
+ if ( isset( $_GET['page'] ) && strpos( $_GET['page'], 'jcf_' ) !== false ) {
+ add_action( 'admin_print_scripts', array( $this, 'add_scripts' ) );
+ add_action( 'admin_print_styles', array( $this, 'add_styles' ) );
} else {
- add_action('admin_init', array($this, 'registerEditAssets') );
+ add_action( 'admin_init', array( $this, 'register_edit_assets' ) );
}
- add_action('admin_print_scripts', array( $this, 'localizeScripts' ));
+ add_action( 'admin_print_scripts', array( $this, 'localize_scripts' ) );
}
/**
* Init menu item and index page for plugin
*/
- public function adminMenu()
- {
- $page_title = \JustCustomFields::$pluginName;
- $page_slug = \JustCustomFields::$pluginSlug;
+ public function admin_menu() {
+ $page_title = \JustCustomFields::$plugin_name;
+ $page_slug = \JustCustomFields::$plugin_slug;
- add_options_page($page_title, $page_title, 'manage_options', 'jcf_admin', array( $this, 'actionIndex' ));
+ add_options_page( $page_title, $page_title, 'manage_options', 'jcf_admin', array( $this, 'action_index' ) );
}
/**
* Render index page
*/
- public function actionIndex()
- {
- $model = new models\Fieldset();
- $count_fields = $model->getFieldsCounter();
- $post_types = jcf_get_post_types('object');
- $taxonomies = jcf_get_taxonomies('objects');
-
- // load template
- return $this->_render('admin/index', array(
- 'tab' => 'fields',
- 'post_types' => $post_types,
- 'taxonomies' => $taxonomies,
- 'count_fields' => $count_fields
- ));
+ public function action_index() {
+ $model = new models\Fieldset();
+ $count_fields = $model->get_fields_counter();
+ $post_types = jcf_get_post_types( 'object' );
+ $taxonomies = jcf_get_taxonomies( 'objects' );
+
+ /*load template*/
+
+ return $this->_render( 'admin/index', array(
+ 'tab' => 'fields',
+ 'post_types' => $post_types,
+ 'taxonomies' => $taxonomies,
+ 'count_fields' => $count_fields,
+ ) );
}
/**
* Include scripts
*/
- public function addScripts()
- {
- $slug = \JustCustomFields::$pluginSlug;
+ public function add_scripts() {
+ $slug = \JustCustomFields::$plugin_slug;
wp_register_script(
$slug,
- jcf_plugin_url('assets/just_custom_fields.js'),
+ jcf_plugin_url( 'assets/just_custom_fields.js' ),
array( 'jquery', 'json2', 'jquery-form', 'jquery-ui-sortable' )
);
- wp_enqueue_script($slug);
- wp_enqueue_script('jquery-ui-autocomplete');
+ wp_enqueue_script( $slug );
+ wp_enqueue_script( 'jquery-ui-autocomplete' );
}
/**
* JS localization text strings
*/
- public function localizeScripts()
- {
- // add text domain
+ public function localize_scripts() {
+ /* add text domain */
$i18n_slug = 'just-custom-fields-i18n';
- wp_register_script($i18n_slug, jcf_plugin_url('assets/jcf_i18n.js'));
- wp_localize_script($i18n_slug, 'jcf_textdomain', jcf_get_language_strings());
- wp_enqueue_script($i18n_slug);
+ wp_register_script( $i18n_slug, jcf_plugin_url( 'assets/jcf_i18n.js' ) );
+ wp_localize_script( $i18n_slug, 'jcf_textdomain', jcf_get_language_strings() );
+ wp_enqueue_script( $i18n_slug );
}
/**
* Include styles
*/
- public function addStyles()
- {
- $slug = \JustCustomFields::$pluginName;
- wp_register_style($slug, jcf_plugin_url('assets/styles.css'), array( 'media-views' ));
- wp_enqueue_style($slug);
+ public function add_styles() {
+ $slug = \JustCustomFields::$plugin_name;
+ wp_register_style( $slug, jcf_plugin_url( 'assets/styles.css' ), array( 'media-views' ) );
+ wp_enqueue_style( $slug );
}
/**
* Register post/term edit assets which can be used in dependency.
*/
- public function registerEditAssets()
- {
+ public function register_edit_assets() {
wp_register_script(
'jcf_edit_post',
- jcf_plugin_url('assets/edit_post.js'),
- array( 'jquery', 'tags-box' )
+ jcf_plugin_url( 'assets/edit_post.js' ),
+ array( 'jquery', 'tags-box' )
);
- wp_register_style('jcf_edit_post', jcf_plugin_url('assets/edit_post.css'));
+ wp_register_style( 'jcf_edit_post', jcf_plugin_url( 'assets/edit_post.css' ) );
}
}
diff --git a/controllers/FieldController.php b/controllers/FieldController.php
index 8951ca1..3830ea5 100644
--- a/controllers/FieldController.php
+++ b/controllers/FieldController.php
@@ -1,108 +1,117 @@
load($_POST) && $field = core\JustFieldFactory::create($model) ) {
- return $this->_renderAjax('fields/form', 'html', array( 'field' => $field ));
+ if ( $model->load( $_POST ) && $field = core\JustFieldFactory::create( $model ) ) {
+ return $this->_render_ajax( 'fields/form', 'html', array( 'field' => $field ) );
}
- return $this->_renderAjax(null, 'json', array( 'status' => !empty($field), 'error' => $model->getErrors() ));
+ return $this->_render_ajax( null, 'json', array(
+ 'status' => ! empty( $field ),
+ 'error' => $model->get_errors(),
+ ) );
}
/**
* Save field data on form submit
*/
- public function ajaxSave()
- {
+ public function ajax_save() {
$model = new models\Field();
- if ( $model->load($_POST) && $success = $model->save() ) {
- if ( isset($success['id_base']) && $success['id_base'] == 'collection' ) {
- $jcf = \JustCustomFields::getInstance();
- $registered_fields = $jcf->getFields('collection');
+ if ( $model->load( $_POST ) && $success = $model->save() ) {
+ if ( isset( $success['id_base'] ) && 'collection' === $success['id_base'] ) {
+ $jcf = \JustCustomFields::get_instance();
+ $registered_fields = $jcf->get_fields( 'collection' );
- $post_type_kind = models\Field::getPostTypeKind($model->post_type);
+ $post_type_kind = models\Field::get_post_type_kind( $model->post_type );
if ( JustField::POSTTYPE_KIND_TAXONOMY == $post_type_kind ) {
- unset($registered_fields['relatedcontent']);
+ unset( $registered_fields['relatedcontent'] );
}
ob_start();
- $this->_render('fields/collection', array(
- 'collection' => $success['instance'],
- 'collection_id' => $success['id'],
- 'fieldset_id' => $success['fieldset_id'],
+ $this->_render( 'fields/collection', array(
+ 'collection' => $success['instance'],
+ 'collection_id' => $success['id'],
+ 'fieldset_id' => $success['fieldset_id'],
'registered_fields' => $registered_fields,
- 'post_type_kind' => $post_type_kind,
- ));
- $success["collection_fields"] = ob_get_clean();
+ 'post_type_kind' => $post_type_kind,
+ ) );
+ $success['collection_fields'] = ob_get_clean();
}
- return $this->_renderAjax(null, 'json', $success);
+ return $this->_render_ajax( null, 'json', $success );
}
- return $this->_renderAjax(null, 'json', array( 'status' => false, 'error' => $model->getErrors() ));
+ return $this->_render_ajax( null, 'json', array( 'status' => false, 'error' => $model->get_errors() ) );
}
/**
* Delete field link callback
*/
- public function ajaxDelete()
- {
+ public function ajax_delete() {
$model = new models\Field();
- $model->load($_POST) && $success = $model->delete();
+ $model->load( $_POST ) && $success = $model->delete();
- return $this->_renderAjax(null, 'json', array( 'status' => !empty($success), 'error' => $model->getErrors() ));
+ return $this->_render_ajax( null, 'json', array(
+ 'status' => ! empty( $success ),
+ 'error' => $model->get_errors(),
+ ) );
}
/**
* Sortable Drop event callback to save changes
*/
- public function ajaxSort()
- {
+ public function ajax_sort() {
$model = new models\Field();
- $model->load($_POST) && $success = $model->sort();
+ $model->load( $_POST ) && $success = $model->sort();
- return $this->_renderAjax(null, 'json', array( 'status' => !empty($success), 'error' => $model->getErrors() ));
+ return $this->_render_ajax( null, 'json', array(
+ 'status' => ! empty( $success ),
+ 'error' => $model->get_errors(),
+ ) );
}
/**
* Sortable Drop event callback to save Collection fields order
*/
- public function ajaxCollectionSort()
- {
+ public function ajax_collection_sort() {
$model = new models\Field();
- $model->load($_POST) && $success = $model->sortCollection();
+ $model->load( $_POST ) && $success = $model->sort_collection();
- return $this->_renderAjax(null, 'json', array( 'status' => !empty($success), 'error' => $model->getErrors() ));
+ return $this->_render_ajax( null, 'json', array(
+ 'status' => ! empty( $success ),
+ 'error' => $model->get_errors(),
+ ) );
}
}
diff --git a/controllers/FieldsetController.php b/controllers/FieldsetController.php
index aaecf09..a58ae29 100644
--- a/controllers/FieldsetController.php
+++ b/controllers/FieldsetController.php
@@ -5,256 +5,270 @@
use jcf\models;
use jcf\core;
-class FieldsetController extends core\Controller
-{
+/**
+ * Fieldset controller
+ */
+class FieldsetController extends core\Controller {
/**
* Init all wp-actions
*/
- public function __construct()
- {
+ public function __construct() {
+
parent::__construct();
- add_action('admin_menu', array( $this, 'initRoutes' ));
-
- //Fieldset actions
- add_action('wp_ajax_jcf_add_fieldset', array( $this, 'ajaxCreate' ));
- add_action('wp_ajax_jcf_delete_fieldset', array( $this, 'ajaxDelete' ));
- add_action('wp_ajax_jcf_change_fieldset', array( $this, 'ajaxGetForm' ));
- add_action('wp_ajax_jcf_update_fieldset', array( $this, 'ajaxUpdate' ));
- add_action('wp_ajax_jcf_order_fieldsets', array( $this, 'ajaxSort' ));
-
- //Visibility options
- add_action('wp_ajax_jcf_get_rule_options', array( $this, 'ajaxGetVisibilityOptions' ));
- add_action('wp_ajax_jcf_get_taxonomy_terms', array( $this, 'ajaGetTaxonomyTerms' ));
- add_action('wp_ajax_jcf_save_visibility_rules', array( $this, 'ajaxSaveVisibility' ));
- add_action('wp_ajax_jcf_add_visibility_rules_form', array( $this, 'ajaxGetVisibilityForm' ));
- add_action('wp_ajax_jcf_delete_visibility_rule', array( $this, 'ajaxDeleteVisibility' ));
- add_action('wp_ajax_jcf_visibility_autocomplete', array( $this, 'ajaxVisibilityAutocomplete' ));
+ add_action( 'admin_menu', array( $this, 'init_routes' ) );
+
+ /* Fieldset actions */
+ add_action( 'wp_ajax_jcf_add_fieldset', array( $this, 'ajax_create' ) );
+ add_action( 'wp_ajax_jcf_delete_fieldset', array( $this, 'ajax_delete' ) );
+ add_action( 'wp_ajax_jcf_change_fieldset', array( $this, 'ajax_get_form' ) );
+ add_action( 'wp_ajax_jcf_update_fieldset', array( $this, 'ajax_update' ) );
+ add_action( 'wp_ajax_jcf_order_fieldsets', array( $this, 'ajax_sort' ) );
+
+ /* Visibility options */
+ add_action( 'wp_ajax_jcf_get_rule_options', array( $this, 'ajax_get_visibility_options' ) );
+ add_action( 'wp_ajax_jcf_get_taxonomy_terms', array( $this, 'ajax_get_taxonomy_terms' ) );
+ add_action( 'wp_ajax_jcf_save_visibility_rules', array( $this, 'ajax_save_visibility' ) );
+ add_action( 'wp_ajax_jcf_add_visibility_rules_form', array( $this, 'ajax_get_visibility_form' ) );
+ add_action( 'wp_ajax_jcf_delete_visibility_rule', array( $this, 'ajax_delete_visibility' ) );
+ add_action( 'wp_ajax_jcf_visibility_autocomplete', array( $this, 'ajax_visibility_autocomplete' ) );
}
/**
* Init routes for settings page with fieldsets and fields
*/
- public function initRoutes()
- {
- $page_title = __('Fields', \JustCustomFields::TEXTDOMAIN);
- add_submenu_page(null, $page_title, $page_title, 'manage_options', 'jcf_fieldset_index', array( $this, 'actionIndex' ));
+ public function init_routes() {
+ $page_title = __( 'Fields', 'jcf' );
+ add_submenu_page( null, $page_title, $page_title, 'manage_options', 'jcf_fieldset_index', array(
+ $this,
+ 'actionIndex',
+ ) );
}
/**
* Render settings page with fieldsets and fields
*/
- public function actionIndex()
- {
- $post_type_id = $_GET['pt'];
- $post_type_kind = models\Fieldset::getPostTypeKind($post_type_id);
+ public function actionIndex() {
+ $post_type_id = $_GET['pt'];
+ $post_type_kind = models\Fieldset::get_post_type_kind( $post_type_id );
- $jcf = \JustCustomFields::getInstance();
+ $jcf = \JustCustomFields::get_instance();
$fieldset_model = new models\Fieldset();
- $field_model = new models\Field();
+ $field_model = new models\Field();
- $fieldsets = $fieldset_model->findByPostType($post_type_id);
- $fields = $field_model->findByPostType($post_type_id);
- $collections = $field_model->findCollectionsByPostType($post_type_id);
- $collections['registered_fields'] = $jcf->getFields('collection');
- $registered_fields = $jcf->getFields();
+ $fieldsets = $fieldset_model->find_by_post_type( $post_type_id );
+ $fields = $field_model->find_by_post_type( $post_type_id );
+ $collections = $field_model->find_collections_by_post_type( $post_type_id );
+ $collections['registered_fields'] = $jcf->get_fields( 'collection' );
+ $registered_fields = $jcf->get_fields();
- if ( core\JustField::POSTTYPE_KIND_TAXONOMY == $post_type_kind ) {
- $post_types = jcf_get_taxonomies('objects');
- // taxonomies are linked to Posts, so we don't need related content here.
+ if ( core\JustField::POSTTYPE_KIND_TAXONOMY === $post_type_kind ) {
+ $post_types = jcf_get_taxonomies( 'objects' );
+ /* taxonomies are linked to Posts, so we don't need related content here. */
unset( $registered_fields['relatedcontent'] );
unset( $collections['registered_fields']['relatedcontent'] );
} else {
- $post_types = jcf_get_post_types('object');
+ $post_types = jcf_get_post_types( 'object' );
}
- // load template
+ /* load template */
$template_params = array(
- 'tab' => 'fields',
- 'post_type' => $post_types[$post_type_id],
- 'post_type_id' => $post_type_id,
- 'post_type_kind' => $post_type_kind,
- 'fieldsets' => $fieldsets,
- 'field_settings' => $fields,
- 'collections' => $collections,
+ 'tab' => 'fields',
+ 'post_type' => $post_types[ $post_type_id ],
+ 'post_type_id' => $post_type_id,
+ 'post_type_kind' => $post_type_kind,
+ 'fieldsets' => $fieldsets,
+ 'field_settings' => $fields,
+ 'collections' => $collections,
'registered_fields' => $registered_fields,
);
- return $this->_render('fieldsets/index', $template_params);
+
+ return $this->_render( 'fieldsets/index', $template_params );
}
/**
* Save NEW fieldset to the data storage (callback)
*/
- public function ajaxCreate()
- {
+ public function ajax_create() {
$model = new models\Fieldset();
- $model->load($_POST) && $success = $model->create();
+ $model->load( $_POST ) && $success = $model->create();
- return $this->_renderAjax(null, 'json', array( 'status' => !empty($success), 'error' => $model->getErrors() ));
+ return $this->_render_ajax( null, 'json', array(
+ 'status' => ! empty( $success ),
+ 'error' => $model->get_errors(),
+ ) );
}
/**
* Delete fieldset link callback
*/
- public function ajaxDelete()
- {
+ public function ajax_delete() {
$model = new models\Fieldset();
- $model->load($_POST) && $success = $model->delete();
+ $model->load( $_POST ) && $success = $model->delete();
- return $this->_renderAjax(null, 'json', array( 'status' => !empty($success), 'error' => $model->getErrors() ));
+ return $this->_render_ajax( null, 'json', array(
+ 'status' => ! empty( $success ),
+ 'error' => $model->get_errors(),
+ ) );
}
/**
* Form html on fieldset Update request
*/
- public function ajaxGetForm()
- {
+ public function ajax_get_form() {
$model = new models\Fieldset();
- if ( $model->load($_POST) && $fieldset = $model->findById($model->fieldset_id) ) {
- $taxonomies = get_object_taxonomies($model->post_type, 'objects');
- $templates = jcf_get_page_templates($model->post_type);
+ if ( $model->load( $_POST ) && $fieldset = $model->find_by_id( $model->fieldset_id ) ) {
+ $taxonomies = get_object_taxonomies( $model->post_type, 'objects' );
+ $templates = jcf_get_page_templates( $model->post_type );
- $post_type_kind = $model->getPostTypeKind($model->post_type);
+ $post_type_kind = $model->get_post_type_kind( $model->post_type );
- return $this->_renderAjax('fieldsets/form', 'html', array(
- 'fieldset' => $fieldset,
- 'post_type' => $model->post_type,
- 'taxonomies' => $taxonomies,
- 'templates' => $templates,
+ return $this->_render_ajax( 'fieldsets/form', 'html', array(
+ 'fieldset' => $fieldset,
+ 'post_type' => $model->post_type,
+ 'taxonomies' => $taxonomies,
+ 'templates' => $templates,
'post_type_kind' => $post_type_kind,
- ));
+ ) );
}
- return $this->_renderAjax(null, 'json', array( 'status' => !empty($fieldset), 'error' => $model->getErrors() ));
+ return $this->_render_ajax( null, 'json', array(
+ 'status' => ! empty( $fieldset ),
+ 'error' => $model->get_errors(),
+ ) );
}
/**
* Update fieldset on form submit
*/
- public function ajaxUpdate()
- {
+ public function ajax_update() {
$model = new models\Fieldset();
- $model->load($_POST) && $success = $model->update();
+ $model->load( $_POST ) && $success = $model->update();
- return $this->_renderAjax(null, 'json', array(
- 'status' => !empty($success),
- 'title' => $model->title,
- 'error' => $model->getErrors()
- ));
+ return $this->_render_ajax( null, 'json', array(
+ 'status' => ! empty( $success ),
+ 'title' => $model->title,
+ 'error' => $model->get_errors(),
+ ) );
}
/**
* Fieldsets order change callback
*/
- public function ajaxSort()
- {
+ public function ajax_sort() {
$model = new models\Fieldset();
- $model->load($_POST) && $success = $model->sort();
+ $model->load( $_POST ) && $success = $model->sort();
- return $this->_renderAjax(null, 'json', array( 'status' => !empty($success), 'error' => $model->getErrors() ));
+ return $this->_render_ajax( null, 'json', array(
+ 'status' => ! empty( $success ),
+ 'error' => $model->get_errors(),
+ ) );
}
/**
- * add form for new rule functions callback
+ * Add form for new rule functions callback
*/
- public function ajaxGetVisibilityForm()
- {
+ public function ajax_get_visibility_form() {
$model = new models\FieldsetVisibility();
- if ( $model->load($_POST) && $form_data = $model->getForm() ) {
- if ( !empty($model->scenario) ) {
- return $this->_renderAjax('fieldsets/visibility/form', 'html', $form_data);
+ if ( $model->load( $_POST ) && $form_data = $model->get_form() ) {
+ if ( ! empty( $model->scenario ) ) {
+ return $this->_render_ajax( 'fieldsets/visibility/form', 'html', $form_data );
}
- return $this->_render('fieldsets/visibility/form', $form_data);
+ return $this->_render( 'fieldsets/visibility/form', $form_data );
}
- return $this->_renderAjax(null, 'json', array( 'status' => !empty($form_data), 'error' => $model->getErrors() ));
+ return $this->_render_ajax( null, 'json', array(
+ 'status' => ! empty( $form_data ),
+ 'error' => $model->get_errors(),
+ ) );
}
/**
- * get base options for visibility rules functions callback
+ * Get base options for visibility rules functions callback
*/
- public function ajaxGetVisibilityOptions()
- {
+ public function ajax_get_visibility_options() {
$model = new models\FieldsetVisibility();
- if ( $model->load($_POST) && $result = $model->getBasedOnOptions() ) {
+ if ( $model->load( $_POST ) && $result = $model->get_based_on_options() ) {
$template = 'taxonomies_list';
- $options = array( 'taxonomies' => $result );
+ $options = array( 'taxonomies' => $result );
- if ( $model->based_on == models\FieldsetVisibility::BASEDON_PAGE_TPL ) {
+ if ( models\FieldsetVisibility::BASEDON_PAGE_TPL === $model->based_on ) {
$template = 'templates_list';
- $options = array( 'templates' => $result );
+ $options = array( 'templates' => $result );
}
- return $this->_renderAjax('fieldsets/visibility/' . $template, 'html', $options);
+ return $this->_render_ajax( 'fieldsets/visibility/' . $template, 'html', $options );
}
- return $this->_renderAjax(null, 'json', array( 'status' => !empty($result), 'error' => $model->getErrors() ));
+ return $this->_render_ajax( null, 'json', array(
+ 'status' => ! empty( $result ),
+ 'error' => $model->get_errors(),
+ ) );
}
/**
* Get taxonomy terms options functions callback
*/
- public function ajaGetTaxonomyTerms()
- {
+ public function ajax_get_taxonomy_terms() {
$taxonomy = $_POST['taxonomy'];
- $terms = get_terms($taxonomy, array( 'hide_empty' => false ));
+ $terms = get_terms( $taxonomy, array( 'hide_empty' => false ) );
- return $this->_renderAjax('fieldsets/visibility/terms_list', 'html', array(
- 'terms' => $terms,
- 'taxonomy' => $taxonomy,
- 'current_term' => array()
- ));
+ return $this->_render_ajax( 'fieldsets/visibility/terms_list', 'html', array(
+ 'terms' => $terms,
+ 'taxonomy' => $taxonomy,
+ 'current_term' => array(),
+ ) );
}
/**
* Save rules for visibility functions callback
*/
- public function ajaxSaveVisibility()
- {
+ public function ajax_save_visibility() {
$model = new models\FieldsetVisibility();
- if ( $model->load($_POST) && $rules = $model->update() ) {
- return $this->_renderAjax('fieldsets/visibility/rules', 'html', array(
+ if ( $model->load( $_POST ) && $rules = $model->update() ) {
+ return $this->_render_ajax( 'fieldsets/visibility/rules', 'html', array(
'visibility_rules' => $rules,
- 'post_type' => $model->post_type
- ));
+ 'post_type' => $model->post_type,
+ ) );
}
- return $this->_renderAjax(null, 'json', array( 'status' => !empty($rules), 'error' => $model->getErrors() ));
+ return $this->_render_ajax( null, 'json', array(
+ 'status' => ! empty( $rules ),
+ 'error' => $model->get_errors(),
+ ) );
}
/**
* Delete rule for visibility functions callback
*/
- public function ajaxDeleteVisibility()
- {
+ public function ajax_delete_visibility() {
$model = new models\FieldsetVisibility();
- if ( $model->load($_POST) && $rules = $model->delete() ) {
- return $this->_renderAjax('fieldsets/visibility/rules', 'html', array(
+ if ( $model->load( $_POST ) && $rules = $model->delete() ) {
+ return $this->_render_ajax( 'fieldsets/visibility/rules', 'html', array(
'visibility_rules' => $rules,
- 'post_type' => $model->post_type
- ));
+ 'post_type' => $model->post_type,
+ ) );
}
- return $this->_renderAjax(array( 'status' => !empty($rules), 'error' => $model->getErrors() ), 'json');
+ return $this->_render_ajax( array( 'status' => ! empty( $rules ), 'error' => $model->get_errors() ), 'json' );
}
/**
* Autocomplete for input for taxonomy terms in visibility form
*/
- public function ajaxVisibilityAutocomplete()
- {
- $taxonomy = strip_tags(trim($_POST['taxonomy']));
- $term = strip_tags(trim($_POST['term']));
- $result = models\FieldsetVisibility::findTaxonomyTerms($taxonomy, $term);
+ public function ajax_visibility_autocomplete() {
+ $taxonomy = strip_tags( trim( $_POST['taxonomy'] ) );
+ $term = strip_tags( trim( $_POST['term'] ) );
+ $result = models\FieldsetVisibility::find_taxonomy_terms( $taxonomy, $term );
- return $this->_renderAjax(null, 'json', $result);
+ return $this->_render_ajax( null, 'json', $result );
}
}
diff --git a/controllers/ImportExportController.php b/controllers/ImportExportController.php
index abe68b2..2a7a736 100644
--- a/controllers/ImportExportController.php
+++ b/controllers/ImportExportController.php
@@ -5,25 +5,32 @@
use jcf\models;
use jcf\core;
-class ImportExportController extends core\Controller
-{
+/**
+ * Import/Export controller
+ */
+class ImportExportController extends core\Controller {
- public function __construct()
- {
+ /**
+ * ImportExportController constructor.
+ * Init WP hooks
+ */
+ public function __construct() {
parent::__construct();
- add_action('admin_menu', array( $this, 'initRoutes' ));
- add_action('wp_ajax_jcf_export_fields_form', array( $this, 'ajaxExportForm' ));
- add_action('wp_ajax_jcf_export_fields', array( $this, 'ajaxExport' ));
- add_action('wp_ajax_jcf_import_fields_form', array( $this, 'ajaxImportForm' ));
+ add_action( 'admin_menu', array( $this, 'init_routes' ) );
+ add_action( 'wp_ajax_jcf_export_fields_form', array( $this, 'ajax_export_form' ) );
+ add_action( 'wp_ajax_jcf_export_fields', array( $this, 'ajax_export' ) );
+ add_action( 'wp_ajax_jcf_import_fields_form', array( $this, 'ajax_import_form' ) );
}
/**
* Init routes for import/export page
*/
- public function initRoutes()
- {
- $page_title = __('Import/Export', \JustCustomFields::TEXTDOMAIN);
- add_submenu_page(null, $page_title, $page_title, 'manage_options', 'jcf_import_export', array( $this, 'actionIndex' ));
+ public function init_routes() {
+ $page_title = __( 'Import/Export', 'jcf' );
+ add_submenu_page( null, $page_title, $page_title, 'manage_options', 'jcf_import_export', array(
+ $this,
+ 'actionIndex',
+ ) );
}
/**
@@ -31,65 +38,67 @@ public function initRoutes()
*
* Also process Import if Import form submitted
*/
- public function actionIndex()
- {
+ public function actionIndex() {
$model = new models\ImportExport();
- $model->load($_POST) && $model->import();
-
- //load template
- return $this->_render('import_export/index', array( 'tab' => 'import_export' ));
+ $model->load( $_POST ) && $model->import();
+
+ /* load template */
+
+ return $this->_render( 'import_export/index', array( 'tab' => 'import_export' ) );
}
/**
* Shows import form popup with import options
* (json file required)
*/
- public function ajaxImportForm()
- {
+ public function ajax_import_form() {
$model = new models\ImportExport();
- if ( $model->load($_POST) && $import_data = $model->getImportFields() ) {
- return $this->_renderAjax('import_export/import', 'html', array('import_data' => $import_data));
+ if ( $model->load( $_POST ) && $import_data = $model->get_import_fields() ) {
+ return $this->_render_ajax( 'import_export/import', 'html', array( 'import_data' => $import_data ) );
}
- return $this->_renderAjax(null, 'json', array( 'status' => !empty($import_data), 'error' => $model->getErrors() ));
+ return $this->_render_ajax( null, 'json', array(
+ 'status' => ! empty( $import_data ),
+ 'error' => $model->get_errors(),
+ ) );
}
/**
* Shows Export form with fields settings for export
*/
- public function ajaxExportForm()
- {
+ public function ajax_export_form() {
$fieldsets_model = new models\Fieldset();
- $fieldsets = $fieldsets_model->findAll();
+ $fieldsets = $fieldsets_model->find_all();
$fields_model = new models\Field();
- $fields = $fields_model->findAll();
+ $fields = $fields_model->find_all();
+
+ /* load template */
- // load template
- return $this->_renderAjax('import_export/export', 'html', array(
+ return $this->_render_ajax( 'import_export/export', 'html', array(
'field_settings' => $fields,
- 'fieldsets' => $fieldsets,
- 'post_types' => jcf_get_post_types()
- ));
+ 'fieldsets' => $fieldsets,
+ 'post_types' => jcf_get_post_types(),
+ ) );
}
/**
* Export fields callback
*/
- public function ajaxExport()
- {
+ public function ajax_export() {
$model = new models\ImportExport();
- if ( $model->load($_POST) && $data = $model->export() ) {
- $filename = 'jcf_export' . date('Ymd-his') . '.json';
- header("Content-Disposition: attachment;filename=" . $filename);
- header("Content-Transfer-Encoding: binary ");
- return $this->_renderAjax(null, 'json', $data);
+ if ( $model->load( $_POST ) && $data = $model->export() ) {
+ $filename = 'jcf_export' . date( 'Ymd-his' ) . '.json';
+ header( 'Content-Disposition: attachment;filename=' . $filename );
+ header( 'Content-Transfer-Encoding: binary' );
+
+ return $this->_render_ajax( null, 'json', $data );
}
- // export failed - all we can is to redirect back to our page
- wp_redirect( get_admin_url(null, 'options-general.php?page=jcf_import_export') );
+ /* export failed - all we can is to redirect back to our page */
+ wp_redirect( get_admin_url( null, 'options-general.php?page=jcf_import_export' ) );
}
}
diff --git a/controllers/MigrateController.php b/controllers/MigrateController.php
index 5de6774..2031f42 100644
--- a/controllers/MigrateController.php
+++ b/controllers/MigrateController.php
@@ -11,26 +11,23 @@
*
* @package jcf\controllers
*/
-class MigrateController extends core\Controller
-{
+class MigrateController extends core\Controller {
/**
* MigrateController constructor.
* Init WP hooks
*/
- public function __construct()
- {
+ public function __construct() {
parent::__construct();
- add_action('admin_menu', array( $this, 'initRoutes' ));
+ add_action( 'admin_menu', array( $this, 'init_routes' ) );
}
/**
* Replace main menu "Just Custom Fields" with migration page
*/
- public function initRoutes()
- {
- $page_title = \JustCustomFields::$pluginName;
+ public function init_routes() {
+ $page_title = \JustCustomFields::$plugin_name;
- add_options_page($page_title, $page_title, 'manage_options', 'jcf_upgrade', array( $this, 'actionIndex' ));
+ add_options_page( $page_title, $page_title, 'manage_options', 'jcf_upgrade', array( $this, 'action_index' ) );
}
/**
@@ -38,37 +35,35 @@ public function initRoutes()
*
* @return bool
*/
- public function actionIndex()
- {
+ public function action_index() {
$model = new models\Migrate();
// check that we have something to migrate.
- $version = $model->getStorageVersion();
- if ( ! version_compare( $version, \JustCustomFields::VERSION, '<') ) {
- return $this->actionUpgraded();
+ $version = $model->get_storage_version();
+ if ( ! version_compare( $version, \JustCustomFields::VERSION, '<' ) ) {
+ return $this->action_upgraded();
}
- $migrations = $model->findMigrations();
+ $migrations = $model->find_migrations();
- // check form submit and migrate
- if ( $model->load($_POST) ) {
- if ( $model->migrate($migrations) ) {
- return $this->actionUpgraded();
+ /* check form submit and migrate */
+ if ( $model->load( $_POST ) ) {
+ if ( $model->migrate( $migrations ) ) {
+ return $this->action_upgraded();
}
- }
- // if no submit we test migrate to show possible warnings
+ } // if no submit we test migrate to show possible warnings
else {
- $warnings = $model->testMigrate($migrations);
+ $warnings = $model->test_migrate( $migrations );
}
- $model->isStorageWritable();
- $errors = $model->getErrors();
+ $model->is_storage_writable();
+ $errors = $model->get_errors();
- return $this->_render('migrate/index', array(
+ return $this->_render( 'migrate/index', array(
'migrations' => $migrations,
- 'warnings' => $warnings,
- 'errors' => $errors,
- ));
+ 'warnings' => $warnings,
+ 'errors' => $errors,
+ ) );
}
/**
@@ -76,9 +71,8 @@ public function actionIndex()
*
* @return bool
*/
- public function actionUpgraded()
- {
- return $this->_render('migrate/upgraded');
+ public function action_upgraded() {
+ return $this->_render( 'migrate/upgraded' );
}
}
diff --git a/controllers/PostTypeController.php b/controllers/PostTypeController.php
index 29ac6b8..22d1dc9 100644
--- a/controllers/PostTypeController.php
+++ b/controllers/PostTypeController.php
@@ -5,169 +5,193 @@
use jcf\models;
use jcf\core;
-class PostTypeController extends core\Controller
-{
+/**
+ * Post Type controller
+ */
+class PostTypeController extends core\Controller {
/**
* Init all wp-actions
*/
- public function __construct()
- {
+ public function __construct() {
parent::__construct();
- if ( $this->_isPostEdit() ) {
- add_action('admin_print_scripts', array( $this, 'addScripts' ));
- add_action('admin_print_styles', array( $this, 'addStyles' ));
- add_action('admin_head', array( $this, 'addMediaUploaderJs' ));
+ if ( $this->_is_post_edit() ) {
+ add_action( 'admin_print_scripts', array( $this, 'add_scripts' ) );
+ add_action( 'admin_print_styles', array( $this, 'add_styles' ) );
+ add_action( 'admin_head', array( $this, 'add_media_uploader_js' ) );
}
- add_action('add_meta_boxes', array( $this, 'actionRender' ), 10, 1);
- add_action('save_post', array( $this, 'savePostExt' ), 10, 2);
+ add_action( 'add_meta_boxes', array( $this, 'action_render' ), 10, 1 );
+ add_action( 'save_post', array( $this, 'save_post_ext' ), 10, 2 );
- // init shortcode
- add_shortcode('jcf-value', array( $this, 'jcfShortcode' ));
+ /* init shortcode */
+ add_shortcode( 'jcf-value', array( $this, 'jcf_shortcode' ) );
}
/**
* Check if we are on Post edit screen (add or update)
*/
- protected function _isPostEdit()
- {
- $is_edit_post = isset($_GET['post']) && isset($_GET['action']) && $_GET['action'] == 'edit';
+ protected function _is_post_edit() {
+ $is_edit_post = isset( $_GET['post'] ) && isset( $_GET['action'] ) && $_GET['action'] == 'edit';
$current_script = '';
- if ( !empty($_SERVER['REQUEST_URI']) ) {
+ if ( ! empty( $_SERVER['REQUEST_URI'] ) ) {
$current_script = $_SERVER['REQUEST_URI'];
}
- if ( !empty($_SERVER['SCRIPT_NAME']) ) {
+ if ( ! empty( $_SERVER['SCRIPT_NAME'] ) ) {
$current_script = $_SERVER['SCRIPT_NAME'];
}
- $is_add_post = strpos($current_script, 'post-new.php') !== FALSE;
+ $is_add_post = strpos( $current_script, 'post-new.php' ) !== false;
return $is_edit_post || $is_add_post;
}
/**
* Get fields by post type
- * @param string $post_type
+ *
+ * @param string $post_type post type.
*/
- public function actionRender( $post_type = '' )
- {
- $model = new models\Fieldset();
- $fieldsets = $model->findByPostType($post_type);
+ public function action_render( $post_type = '' ) {
+ $model = new models\Fieldset();
+ $fieldsets = $model->find_by_post_type( $post_type );
$field_model = new models\Field();
- $fields = $field_model->findByPostType($post_type);
+ $fields = $field_model->find_by_post_type( $post_type );
$visibility_model = new models\FieldsetVisibility();
- $visibility_rules = $visibility_model->findByPostType($post_type);
+ $visibility_rules = $visibility_model->find_by_post_type( $post_type );
- if ( !empty($fieldsets) ) {
- // remove fieldsets without fields
+ if ( ! empty( $fieldsets ) ) {
+ /* remove fieldsets without fields */
foreach ( $fieldsets as $f_id => $fieldset ) {
- // if all fields disabled -> remove fieldset
- if ( empty($fieldset['fields']) ) continue;
-
- foreach ($fieldset['fields'] as $field_id => $enabled) {
- if ( !$enabled || empty( $fields[$field_id] ) ) continue;
-
+ /* if all fields disabled -> remove fieldset */
+ if ( empty( $fieldset['fields'] ) ) {
+ continue;
+ }
+ foreach ( $fieldset['fields'] as $field_id => $enabled ) {
+ if ( ! $enabled || empty( $fields[ $field_id ] ) ) {
+ continue;
+ }
$params = array(
- 'post_type' => $post_type,
- 'field_id' => $field_id,
- 'fieldset_id' => $fieldset['id']
+ 'post_type' => $post_type,
+ 'field_id' => $field_id,
+ 'fieldset_id' => $fieldset['id'],
);
- $field_model->load($params) && $field_obj = core\JustFieldFactory::create($field_model);
- if ( !$field_obj ) continue;
+ $field_model->load( $params ) && $field_obj = core\JustFieldFactory::create( $field_model );
+ if ( ! $field_obj ) {
+ continue;
+ }
- $field_obj->doAddJs();
- $field_obj->doAddCss();
+ $field_obj->do_add_js();
+ $field_obj->do_add_css();
}
- $pos = isset($fieldset['position'])? $fieldset['position'] : models\Fieldset::POSITION_ADVANCED;
- $prio = isset($fieldset['priority'])? $fieldset['priority'] : models\Fieldset::PRIO_DEFAULT;
+ $pos = isset( $fieldset['position'] ) ? $fieldset['position'] : models\Fieldset::POSITION_ADVANCED;
+ $prio = isset( $fieldset['priority'] ) ? $fieldset['priority'] : models\Fieldset::PRIO_DEFAULT;
- add_meta_box('jcf_fieldset-' . $f_id, $fieldset['title'], array( $this, 'renderCustomField' ), $post_type, $pos, $prio, array( $fieldset ));
+ add_meta_box( 'jcf_fieldset-' . $f_id, $fieldset['title'], array(
+ $this,
+ 'render_custom_field',
+ ), $post_type, $pos, $prio, array( $fieldset ) );
}
- wp_add_inline_script('jquery-core', 'var jcf_fieldsets_visibility_rules = ' . json_encode($visibility_rules) . ';', 'before');
+ wp_add_inline_script( 'jquery-core', 'var jcf_fieldsets_visibility_rules = ' . json_encode( $visibility_rules ) . ';', 'before' );
}
}
/**
- * prepare and print fieldset html.
- * - load each field class
- * - print form from each class
+ * Prepare and print fieldset html.
+ * - load each field class
+ * - print form from each class
+ *
+ * @param array $post post.
+ * @param array $box box.
*/
- public function renderCustomField( $post = NULL, $box = NULL )
- {
- $model = new models\Field();
+ public function render_custom_field( $post = null, $box = null ) {
+ $model = new models\Field();
$fieldset = $box['args'][0];
- $fields = $model->findByPostType($post->post_type);
- $this->_render('shortcodes/modal');
+ $fields = $model->find_by_post_type( $post->post_type );
+ $this->_render( 'shortcodes/modal' );
foreach ( $fieldset['fields'] as $field_id => $enabled ) {
- if ( !$enabled || empty( $fields[$field_id] ) ) continue;
+ if ( ! $enabled || empty( $fields[ $field_id ] ) ) {
+ continue;
+ }
$params = array(
- 'post_type' => $post->post_type,
- 'field_id' => $field_id,
+ 'post_type' => $post->post_type,
+ 'field_id' => $field_id,
'fieldset_id' => $fieldset['id'],
);
- $model->load($params) && $field_obj = core\JustFieldFactory::create($model);
- if ( !$field_obj ) continue;
-
- $field_obj->setPostID($post->ID);
+ $model->load( $params ) && $field_obj = core\JustFieldFactory::create( $model );
+ if ( ! $field_obj ) {
+ continue;
+ }
+
+ $field_obj->set_post_id( $post->ID );
$field_obj->field();
}
- unset($field_obj);
+ unset( $field_obj );
- // Use nonce for verification
+ /* Use nonce for verification */
global $jcf_noncename;
- if ( empty($jcf_noncename) ) {
- wp_nonce_field(plugin_basename(__FILE__), 'justcustomfields_noncename');
+ if ( empty( $jcf_noncename ) ) {
+ wp_nonce_field( plugin_basename( __FILE__ ), 'justcustomfields_noncename' );
$jcf_noncename = true;
}
}
-
+
/**
* Save values of custom fields for post
- * @param int $post_ID
- * @param array $post
+ *
+ * @param int $post_id post ID.
+ * @param array $post post.
+ *
+ * @return bool
*/
- public function savePostExt( $post_ID = 0, $post = null )
- {
+ public function save_post_ext( $post_id = 0, $post = null ) {
$fieldsets_model = new models\Fieldset();
- $field_model = new models\Field();
- $field_model->load($_POST);
- // do not save anything on autosave
- if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return;
+ $field_model = new models\Field();
+ $field_model->load( $_POST );
+ /* do not save anything on autosave */
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
+ return;
+ }
- // verify this came from the our screen and with proper authorization,
- // because save_post can be triggered at other times
- if ( empty($_POST['justcustomfields_noncename']) || !wp_verify_nonce($_POST['justcustomfields_noncename'], plugin_basename(__FILE__)) )
+ /*
+ * Verify this came from the our screen and with proper authorization,
+ * because save_post can be triggered at other times
+ */
+ if ( empty( $_POST['justcustomfields_noncename'] ) || ! wp_verify_nonce( $_POST['justcustomfields_noncename'], plugin_basename( __FILE__ ) ) ) {
return;
+ }
- // check permissions
- $permission = ('page' == $field_model->post_type) ? 'edit_page' : 'edit_post';
+ /* check permissions */
+ $permission = ( 'page' === $field_model->post_type ) ? 'edit_page' : 'edit_post';
- if ( !current_user_can($permission, $post_ID) ) return;
+ if ( ! current_user_can( $permission, $post_id ) ) {
+ return;
+ }
- // OK, we're authenticated: we need to find and save the data
- // get fieldsets
+ /*
+ * OK, we're authenticated: we need to find and save the data
+ * get fieldsets
+ */
- $fieldsets = $fieldsets_model->findByPostType($field_model->post_type);
+ $fieldsets = $fieldsets_model->find_by_post_type( $field_model->post_type );
- // create field class objects and call save function
+ /* create field class objects and call save function */
foreach ( $fieldsets as $f_id => $fieldset ) {
$field_model->fieldset_id = $fieldset['id'];
foreach ( $fieldset['fields'] as $field_id => $tmp ) {
$field_model->field_id = $field_id;
- $field_obj = core\JustFieldFactory::create($field_model);
- $field_obj->setPostID($post->ID);
- $field_obj->doSave();
+ $field_obj = core\JustFieldFactory::create( $field_model );
+ $field_obj->set_post_id( $post->ID );
+ $field_obj->do_save();
}
}
@@ -176,56 +200,60 @@ public function savePostExt( $post_ID = 0, $post = null )
/**
* Set value of shortcode
+ *
+ * @param array $args args.
+ *
+ * @return string
*/
- public function jcfShortcode( $args )
- {
+ public function jcf_shortcode( $args ) {
$model = new models\Shortcodes();
- return $model->getFieldValue($args);
+
+ return $model->get_field_value( $args );
}
/**
- * add custom scripts to post edit page
+ * Add custom scripts to post edit page
*/
- public function addScripts()
- {
- wp_enqueue_script('jcf_edit_post');
+ public function add_scripts() {
+ wp_enqueue_script( 'jcf_edit_post' );
}
/**
- * add custom styles to post edit page
+ * Add custom styles to post edit page
*/
- public function addStyles()
- {
- wp_enqueue_style('jcf_edit_post');
+ public function add_styles() {
+ wp_enqueue_style( 'jcf_edit_post' );
}
/**
- * this add js script to the Upload Media wordpress popup
+ * This add js script to the Upload Media wordpress popup
*/
- public function addMediaUploaderJs()
- {
+ public function add_media_uploader_js() {
global $pagenow;
- if ( $pagenow != 'media-upload.php' || empty($_GET['jcf_media']) )
+ if ( 'media-upload.php' !== $pagenow || empty( $_GET['jcf_media'] ) ) {
return;
+ }
- // Gets the right label depending on the caller widget
- switch ( $_GET['type'] )
- {
- case 'image': $button_label = __('Select Picture', \JustCustomFields::TEXTDOMAIN);
+ /* Gets the right label depending on the caller widget */
+ switch ( $_GET['type'] ) {
+ case 'image':
+ $button_label = __( 'Select Picture', 'jcf' );
break;
- case 'file': $button_label = __('Select File', \JustCustomFields::TEXTDOMAIN);
+ case 'file':
+ $button_label = __( 'Select File', 'jcf' );
break;
- default: $button_label = __('Insert into Post', \JustCustomFields::TEXTDOMAIN);
+ default:
+ $button_label = __( 'Insert into Post', 'jcf' );
break;
}
- // Overrides the label when displaying the media uploader panels
+ /* Overrides the label when displaying the media uploader panels */
?>
diff --git a/controllers/SettingsController.php b/controllers/SettingsController.php
index be0b528..18e07e4 100755
--- a/controllers/SettingsController.php
+++ b/controllers/SettingsController.php
@@ -5,46 +5,49 @@
use jcf\models;
use jcf\core;
-class SettingsController extends core\Controller
-{
+/**
+ * Settings controller
+ */
+class SettingsController extends core\Controller {
/**
* Init all wp-actions
*/
- public function __construct()
- {
+ public function __construct() {
parent::__construct();
- add_action('admin_menu', array( $this, 'initRoutes' ));
+ add_action( 'admin_menu', array( $this, 'init_routes' ) );
}
/**
* Init routes for settings page
*/
- public function initRoutes()
- {
- $page_title = __('Settings', \JustCustomFields::TEXTDOMAIN);
- add_submenu_page(null, $page_title, $page_title, 'manage_options', 'jcf_settings', array( $this, 'actionIndex' ));
+ public function init_routes() {
+ $page_title = __( 'Settings', 'jcf' );
+ add_submenu_page( null, $page_title, $page_title, 'manage_options', 'jcf_settings', array(
+ $this,
+ 'action_index',
+ ) );
}
/**
* Render settings page
*/
- public function actionIndex()
- {
+ public function action_index() {
$model = new models\Settings();
- $model->load($_POST) && $model->save();
-
- $source = $model::getDataSourceType();
- $network = $model::getNetworkMode();
- $googlemaps_api_key = $model::getGoogleMapsApiKey();
-
- // load template
- return $this->_render('settings/index', array(
- 'tab' => 'settings',
- 'source' => $source,
- 'network' => $network,
- 'googlemaps_api_key' => $googlemaps_api_key,
- ));
+ $model->load( $_POST ) && $model->save();
+
+ $source = $model::get_data_source_type();
+ $network = $model::get_network_mode();
+ $googlemaps_api_key = $model::get_google_maps_api_key();
+
+ /* load template */
+
+ return $this->_render( 'settings/index', array(
+ 'tab' => 'settings',
+ 'source' => $source,
+ 'network' => $network,
+ 'googlemaps_api_key' => $googlemaps_api_key,
+ ) );
}
}
diff --git a/controllers/TaxonomyController.php b/controllers/TaxonomyController.php
index 1f55899..d765a6c 100644
--- a/controllers/TaxonomyController.php
+++ b/controllers/TaxonomyController.php
@@ -6,54 +6,60 @@
use jcf\core;
use jcf\core\JustField;
-class TaxonomyController extends core\Controller
-{
+/**
+ * Taxonomy controller
+ */
+class TaxonomyController extends core\Controller {
+
+ /**
+ * Taxonomy var
+ *
+ * @var $_taxonomy
+ */
protected $_taxonomy = null;
/**
* Init all wp-actions
*/
- public function __construct()
- {
+ public function __construct() {
parent::__construct();
- if ( $this->_isTaxonomyEdit() ) {
- add_action('admin_print_scripts', array( $this, 'addScripts' ));
- add_action('admin_print_styles', array( $this, 'addStyles' ));
- add_action('admin_head', array( $this, 'addMediaUploaderJs' ));
+ if ( $this->_is_taxonomy_edit() ) {
+ add_action( 'admin_print_scripts', array( $this, 'add_scripts' ) );
+ add_action( 'admin_print_styles', array( $this, 'add_styles' ) );
+ add_action( 'admin_head', array( $this, 'add_media_uploader_js' ) );
- add_action( $this->_taxonomy . '_edit_form_fields', array($this, 'actionRender'), 10, 2 );
- add_action( $this->_taxonomy . '_add_form_fields', array($this, 'actionRender'), 10, 2 );
+ add_action( $this->_taxonomy . '_edit_form_fields', array( $this, 'action_render' ), 10, 2 );
+ add_action( $this->_taxonomy . '_add_form_fields', array( $this, 'action_render' ), 10, 2 );
}
- add_action( 'edit_terms', array($this, 'saveCustomFields'), 10, 3 );
- add_action( 'create_term', array($this, 'saveCustomFields'), 10, 3 );
+ add_action( 'edit_terms', array( $this, 'save_custom_fields' ), 10, 3 );
+ add_action( 'create_term', array( $this, 'save_custom_fields' ), 10, 3 );
- add_action( 'wp_ajax_jcf_ajax_get_taxonomy_custom_fields', array($this, 'ajaxRenderFields') );
+ add_action( 'wp_ajax_jcf_ajax_get_taxonomy_custom_fields', array( $this, 'ajax_render_fields' ) );
}
-
+
/**
* Check if we are on Taxonomy edit screen (add or update)
*/
- protected function _isTaxonomyEdit()
- {
+ protected function _is_taxonomy_edit() {
$is_edit_taxonomy = false;
- if ( !empty($_GET['taxonomy']) ) {
+ if ( ! empty( $_GET['taxonomy'] ) ) {
$is_edit_taxonomy = true;
- $this->_taxonomy = $_GET['taxonomy'];
+ $this->_taxonomy = $_GET['taxonomy'];
}
$current_script = '';
- if ( !empty($_SERVER['REQUEST_URI']) ) {
+ if ( ! empty( $_SERVER['REQUEST_URI'] ) ) {
$current_script = $_SERVER['REQUEST_URI'];
}
- if ( !empty($_SERVER['SCRIPT_NAME']) ) {
+ if ( ! empty( $_SERVER['SCRIPT_NAME'] ) ) {
$current_script = $_SERVER['SCRIPT_NAME'];
}
$is_add_term = false;
- if (strpos($current_script, 'term.php') !== FALSE
- || strpos($current_script, 'edit-tags.php') !== FALSE
+ if ( strpos( $current_script, 'term.php' ) !== false
+ || strpos( $current_script, 'edit-tags.php' ) !== false
) {
$is_add_term = true;
}
@@ -64,21 +70,22 @@ protected function _isTaxonomyEdit()
/**
* Taxonomy form render hook
*
- * @param \WP_Term|null $term
+ * @param \WP_Term|null $term term.
*/
- public function actionRender( $term = null )
- {
+ public function action_render( $term = null ) {
$is_edit = false;
- if ( !empty($term->term_id) ) $is_edit = true;
+ if ( ! empty( $term->term_id ) ) {
+ $is_edit = true;
+ }
$post_type = JustField::POSTTYPE_KIND_PREFIX_TAXONOMY . $this->_taxonomy;
- $model = new models\Fieldset();
- $fieldsets = $model->findByPostType($post_type);
+ $model = new models\Fieldset();
+ $fieldsets = $model->find_by_post_type( $post_type );
- if ( !empty($fieldsets) ) {
+ if ( ! empty( $fieldsets ) ) {
print '
';
- $this->_renderFieldsets($fieldsets, $post_type, $is_edit? $term->term_id : null);
+ $this->_render_fieldsets( $fieldsets, $post_type, $is_edit ? $term->term_id : null );
print '
';
}
@@ -87,54 +94,57 @@ public function actionRender( $term = null )
/**
* Print taxonomy custom fields
*
- * @param array $fieldsets Fieldsets settings
- * @param string $post_type Post type ID
- * @param int $term_id Object ID (for edit mode)
+ * @param array $fieldsets Fieldsets settings.
+ * @param string $post_type Post type ID.
+ * @param int $term_id Object ID (for edit mode).
*/
- protected function _renderFieldsets( $fieldsets, $post_type, $term_id )
- {
+ protected function _render_fieldsets( $fieldsets, $post_type, $term_id ) {
$field_model = new models\Field();
foreach ( $fieldsets as $f_id => $fieldset ) {
foreach ( $fieldset['fields'] as $field_id => $enabled ) {
- if ( !$enabled ) {
- unset($fieldset['fields'][$field_id]);
+ if ( ! $enabled ) {
+ unset( $fieldset['fields'][ $field_id ] );
}
}
- // if all fields disabled -> remove fieldset
- if ( empty($fieldset['fields']) ) continue;
+ /* if all fields disabled -> remove fieldset */
+ if ( empty( $fieldset['fields'] ) ) {
+ continue;
+ }
- $htmlFields = '';
- foreach ($fieldset['fields'] as $field_id => $enabled) {
+ $html_fields = '';
+ foreach ( $fieldset['fields'] as $field_id => $enabled ) {
$params = array(
- 'post_type' => $post_type,
- 'field_id' => $field_id,
- 'fieldset_id' => $fieldset['id']
+ 'post_type' => $post_type,
+ 'field_id' => $field_id,
+ 'fieldset_id' => $fieldset['id'],
);
- $field_model->load($params) && $field_obj = core\JustFieldFactory::create($field_model);
- if ( !$field_obj ) continue;
+ $field_model->load( $params ) && $field_obj = core\JustFieldFactory::create( $field_model );
+ if ( ! $field_obj ) {
+ continue;
+ }
if ( $term_id ) {
- $field_obj->setPostID($term_id);
+ $field_obj->set_post_id( $term_id );
}
- $field_obj->doAddJs();
- $field_obj->doAddCss();
+ $field_obj->do_add_js();
+ $field_obj->do_add_css();
- $field_obj->fieldOptions['after_title'] = ': ';
+ $field_obj->field_options['after_title'] = ': ';
ob_start();
$field_obj->field();
- $htmlFields .= ob_get_clean();
+ $html_fields .= ob_get_clean();
}
- $this->_render('fieldsets/_taxonomy_meta_box', array(
- 'name' => $fieldset['title'],
- 'content' => $htmlFields,
- 'is_edit' => (int)$term_id,
- ));
+ $this->_render( 'fieldsets/_taxonomy_meta_box', array(
+ 'name' => $fieldset['title'],
+ 'content' => $html_fields,
+ 'is_edit' => (int) $term_id,
+ ) );
}
}
@@ -144,112 +154,109 @@ protected function _renderFieldsets( $fieldsets, $post_type, $term_id )
* Called after tag created, because the page does not refreshed automatically
* and we need to reset all fields data.
*/
- public function ajaxRenderFields()
- {
+ public function ajax_render_fields() {
$post_type = JustField::POSTTYPE_KIND_PREFIX_TAXONOMY . $_POST['taxonomy'];
$fieldsets_model = new models\Fieldset();
- $fieldsets = $fieldsets_model->findByPostType($post_type);
+ $fieldsets = $fieldsets_model->find_by_post_type( $post_type );
- if ( empty($fieldsets) ) {
+ if ( empty( $fieldsets ) ) {
exit();
}
- header("Content-Type: text/html; charset=" . get_bloginfo('charset'));
- $this->_renderFieldsets($fieldsets, $post_type, null);
+ header( 'Content-Type: text/html; charset=' . get_bloginfo( 'charset' ) );
+ $this->_render_fieldsets( $fieldsets, $post_type, null );
exit;
}
/**
* Save custom fields to term meta.
*
- * @param int $term_id
- * @param string $tt_id
- * @param string|null $taxonomy
+ * @param int $term_id Term ID.
+ * @param string $tt_id TT ID.
+ * @param string|null $taxonomy Taxonomy.
*
* @return bool|void
*/
- public function saveCustomFields( $term_id, $tt_id, $taxonomy = null )
- {
- $post_type = empty($taxonomy) ? $tt_id : $taxonomy;
- $post_type = JustField::POSTTYPE_KIND_PREFIX_TAXONOMY . $post_type;
-
+ public function save_custom_fields( $term_id, $tt_id, $taxonomy = null ) {
+ $post_type = empty( $taxonomy ) ? $tt_id : $taxonomy;
+ $post_type = JustField::POSTTYPE_KIND_PREFIX_TAXONOMY . $post_type;
$fieldsets_model = new models\Fieldset();
- $fieldsets = $fieldsets_model->findByPostType($post_type);
- if ( empty($fieldsets) ) {
+ $fieldsets = $fieldsets_model->find_by_post_type( $post_type );
+ if ( empty( $fieldsets ) ) {
return;
}
- $field_model = new models\Field();
+ $field_model = new models\Field();
$field_model->post_type = $post_type;
- // create field class objects and call save function
+ /* Create field class objects and call save function */
foreach ( $fieldsets as $f_id => $fieldset ) {
$field_model->fieldset_id = $fieldset['id'];
foreach ( $fieldset['fields'] as $field_id => $tmp ) {
$field_model->field_id = $field_id;
- $field_obj = core\JustFieldFactory::create($field_model);
- $field_obj->setPostID($term_id);
- $field_obj->doSave();
+ $field_obj = core\JustFieldFactory::create( $field_model );
+ $field_obj->set_post_id( $term_id );
+ $field_obj->do_save();
}
}
return false;
}
-
+
/**
- * add custom scripts to post edit page
+ * Add custom scripts to post edit page
*/
- public function addScripts()
- {
+ public function add_scripts() {
wp_register_script(
'jcf_edit_taxonomy',
- jcf_plugin_url('assets/edit_taxonomy.js'),
+ jcf_plugin_url( 'assets/edit_taxonomy.js' ),
array( 'jquery' )
);
- wp_enqueue_script('jcf_edit_taxonomy');
+ wp_enqueue_script( 'jcf_edit_taxonomy' );
}
/**
- * add custom styles to post edit page
+ * Add custom styles to post edit page
*/
- public function addStyles()
- {
- wp_enqueue_style('jcf_edit_post');
-
- wp_register_style('jcf_edit_taxonomy', WP_PLUGIN_URL . '/just-custom-fields/assets/edit_taxonomy.css');
- wp_enqueue_style('jcf_edit_taxonomy');
+ public function add_styles() {
+ wp_enqueue_style( 'jcf_edit_post' );
+
+ wp_register_style( 'jcf_edit_taxonomy', WP_PLUGIN_URL . '/just-custom-fields/assets/edit_taxonomy.css' );
+ wp_enqueue_style( 'jcf_edit_taxonomy' );
}
-
+
/**
- * this add js script to the Upload Media wordpress popup
+ * This add js script to the Upload Media wordpress popup
*/
- public function addMediaUploaderJs()
- {
+ public function add_media_uploader_js() {
global $pagenow;
- if ( $pagenow != 'media-upload.php' || empty($_GET ['jcf_media']) )
+ if ( 'media-upload.php' !== $pagenow || empty( $_GET ['jcf_media'] ) ) {
return;
+ }
- // Gets the right label depending on the caller widget
- switch ( $_GET ['type'] )
- {
- case 'image': $button_label = __('Select Picture', \JustCustomFields::TEXTDOMAIN);
+ /* Gets the right label depending on the caller widget */
+ switch ( $_GET ['type'] ) {
+ case 'image':
+ $button_label = __( 'Select Picture', 'jcf' );
break;
- case 'file': $button_label = __('Select File', \JustCustomFields::TEXTDOMAIN);
+ case 'file':
+ $button_label = __( 'Select File', 'jcf' );
break;
- default: $button_label = __('Insert into Post', \JustCustomFields::TEXTDOMAIN);
+ default:
+ $button_label = __( 'Insert into Post', 'jcf' );
break;
}
- // Overrides the label when displaying the media uploader panels
+ /* Overrides the label when displaying the media uploader panels */
?>
diff --git a/core/Autoload.php b/core/Autoload.php
index 664c0de..7315191 100644
--- a/core/Autoload.php
+++ b/core/Autoload.php
@@ -5,38 +5,35 @@
/**
* SPL autoload registration for plugin to prevent using file includes
*/
-class Autoloader
-{
+class Autoload {
/**
* Class contructor register SPL autoload callback function
*/
- public function __construct()
- {
- spl_autoload_register(array( $this, 'loader' ));
+ public function __construct() {
+ spl_autoload_register( array( $this, 'loader' ) );
}
/**
* Search for the class by namespace path and include it if found.
- *
- * @param string $class_name
+ *
+ * @param string $class_name Class name.
*/
- public function loader( $class_name )
- {
- $class_path = str_replace('\\', '/', $class_name);
+ public function loader( $class_name ) {
+ $class_path = str_replace( '\\', '/', $class_name );
- // check if this class is related to the plugin namespace. exit if not
- if ( strpos($class_path, 'jcf') !== 0 ) {
+ /* check if this class is related to the plugin namespace. exit if not */
+ if ( strpos( $class_path, 'jcf' ) !== 0 ) {
return;
}
- $path = preg_replace('/^jcf\//', JCF_ROOT . '/', $class_path) . '.php';
+ $path = preg_replace( '/^jcf\//', JCF_ROOT . '/', $class_path ) . '.php';
- if ( is_file($path) ) {
+ if ( is_file( $path ) ) {
require_once( $path );
}
}
}
-new Autoloader();
+new Autoload();
diff --git a/core/Controller.php b/core/Controller.php
index 80f0f66..ba41b97 100755
--- a/core/Controller.php
+++ b/core/Controller.php
@@ -3,28 +3,24 @@
namespace jcf\core;
/**
- * Main controller
+ * Main controller
*/
-class Controller
-{
+class Controller {
/**
* Controller constructor.
*/
- public function __construct()
- {
-
- }
+ public function __construct(){}
/**
* Function for render views
- * @param string $template file name to be rendered
- * @param array $params array of variables to be passed to the view file
+ *
+ * @param string $template file name to be rendered.
+ * @param array $params array of variables to be passed to the view file.
* @return boolean
*/
- protected function _render( $template, $params = array() )
- {
- extract($params);
+ protected function _render( $template, $params = array() ) {
+ extract( $params );
include( JCF_ROOT . '/views/' . $template . '.php' );
return true;
@@ -34,20 +30,18 @@ protected function _render( $template, $params = array() )
* Function for render views inside AJAX request
* Echo rendered content directly in output buffer
*
- * @param string $template file name to be rendered
- * @param string $format json|html control which header content type should be sent
- * @param array $params array of variables to be passed to the view file
+ * @param string $template file name to be rendered.
+ * @param string $format json|html control which header content type should be sent.
+ * @param array $params array of variables to be passed to the view file.
*/
- protected function _renderAjax( $template = null, $format, $params = array() )
- {
- if ( $format == 'json' ) {
- $responce = json_encode($params);
- header("Content-Type: application/json; charset=" . get_bloginfo('charset'));
- }
- else {
- header("Content-Type: text/html; charset=" . get_bloginfo('charset'));
+ protected function _render_ajax( $template = null, $format, $params = array() ) {
+ if ( 'json' === $format ) {
+ $responce = json_encode( $params );
+ header( 'Content-Type: application/json; charset=' . get_bloginfo( 'charset' ) );
+ } else {
+ header( 'Content-Type: text/html; charset=' . get_bloginfo( 'charset' ) );
ob_start();
- $this->_render($template, $params);
+ $this->_render( $template, $params );
$responce = ob_get_clean();
}
echo $responce;
diff --git a/core/DataLayer.php b/core/DataLayer.php
index 7768a1e..ffb28db 100755
--- a/core/DataLayer.php
+++ b/core/DataLayer.php
@@ -6,17 +6,16 @@
* Abstract class for all data layers
* Define methods to be defined in every child DataLayer
*/
-abstract class DataLayer
-{
+abstract class DataLayer {
/**
- * fields settings
+ * Fields settings
*
* @var array
*/
protected $_fields = array();
/**
- * fieldset settings
+ * Fieldset settings
*
* @var array
*/
@@ -27,10 +26,9 @@ abstract class DataLayer
*
* On create find fields and fieldsets
*/
- public function __construct()
- {
- $this->setFields();
- $this->setFieldsets();
+ public function __construct() {
+ $this->set_fields();
+ $this->set_fieldsets();
}
/**
@@ -38,8 +36,7 @@ public function __construct()
*
* @return array
*/
- public function getFields()
- {
+ public function get_fields() {
return $this->_fields;
}
@@ -48,53 +45,55 @@ public function getFields()
*
* @return array
*/
- public function getFieldsets()
- {
+ public function get_fieldsets() {
return $this->_fieldsets;
}
/**
* Method to get version of storage
- *
+ *
* @return array
*/
- abstract public function getStorageVersion();
+ abstract public function get_storage_version();
/**
* Method to update version of storage till last
*
- * @param float|null $version
+ * @param float|null $version Version.
+ *
* @return boolean
*/
- abstract public function saveStorageVersion( $version = null );
+ abstract public function save_storage_version( $version = null );
/**
* Fields settings setter
*
- * @param array|null $fields
+ * @param array|null $fields Fields.
+ *
* @return mixed
*/
- abstract public function setFields( $fields = null );
+ abstract public function set_fields( $fields = null );
/**
* Method to save fields settings into the storage collector
*
* @return mixed
*/
- abstract public function saveFieldsData();
+ abstract public function save_fields_data();
/**
* Fieldsets settings setter
*
- * @param array|null $fields
+ * @param array|null $fieldsets Fieldsets.
+ *
* @return mixed
*/
- abstract public function setFieldsets( $fieldsets = null );
+ abstract public function set_fieldsets( $fieldsets = null );
/**
* Method to save fieldsets settings into the storage collector
*
* @return mixed
*/
- abstract public function saveFieldsetsData();
+ abstract public function save_fieldsets_data();
}
diff --git a/core/DataLayerFactory.php b/core/DataLayerFactory.php
index 9d69b19..7f27916 100755
--- a/core/DataLayerFactory.php
+++ b/core/DataLayerFactory.php
@@ -8,22 +8,22 @@
* Class DataLayerFactory
* Factory to create DataLater object based on plugin settings
*/
-class DataLayerFactory
-{
+class DataLayerFactory {
/**
* Create data layer object
- * @param string $source_type database|fs_theme|fs_global / similar to models\Settings::CONF_SOURCE_*
+ *
+ * @param string $source_type database|fs_theme|fs_global / similar to models\Settings::CONF_SOURCE_*.
+ *
* @return \jcf\core\DataLayer
*/
- public static function create( $source_type = null )
- {
- if ( is_null($source_type) ) {
- $source_type = models\Settings::getDataSourceType();
+ public static function create( $source_type = null ) {
+ if ( is_null( $source_type ) ) {
+ $source_type = models\Settings::get_data_source_type();
}
- $layer_class = ($source_type == models\Settings::CONF_SOURCE_DB) ? 'DBDataLayer' : 'FilesDataLayer';
+ $layer_class = ( models\Settings::CONF_SOURCE_DB === $source_type ) ? 'DBDataLayer' : 'FilesDataLayer';
$layer_class = '\\jcf\\models\\' . $layer_class;
+
return new $layer_class();
}
-
}
diff --git a/core/JustField.php b/core/JustField.php
index c2ba1dd..32f6b9d 100644
--- a/core/JustField.php
+++ b/core/JustField.php
@@ -5,8 +5,10 @@
use jcf\models;
use jcf\core;
-class JustField
-{
+/**
+ * Class JustField
+ */
+class JustField {
const POSTTYPE_KIND_PREFIX_TAXONOMY = 'TAX_';
const POSTTYPE_KIND_PREFIX_POST = '';
@@ -15,163 +17,240 @@ class JustField
/**
* Root id for all fields of this type (field type)
+ *
+ * @var string
+ */
+ public $id_base;
+
+ /**
+ * Compatibility with WP version + it >=, - it <
+ *
+ * @var string
+ */
+ public static $compatibility = '3.0+';
+
+ /**
+ * Name for this field type
+ *
+ * @var string
+ */
+ public $title;
+
+ /**
+ * Slug for this field type.
+ *
* @var string
*/
- public $idBase;
- public static $compatibility = '3.0+'; // compatibility with WP version + it >=, - it <
- public $title; // Name for this field type.
public $slug = null;
- public $fieldOptions = array(
- 'classname' => 'jcf_custom_field',
+
+ /**
+ * Field options for this field type.
+ *
+ * @var array
+ */
+ public $field_options = array(
+ 'classname' => 'jcf_custom_field',
'before_widget' => '
',
- 'after_widget' => '
',
- 'before_title' => '
',
- 'after_title' => ': '
+ 'after_widget' => '
',
+ 'before_title' => '',
+ 'after_title' => ': ',
);
- public $isNew = false;
/**
- * check for change field name if it edit on post edit page
+ * Root id for all fields of this type (field type)
+ *
+ * @var string
+ */
+ public $is_new = false;
+
+ /**
+ * Check for change field name if it edit on post edit page
+ *
+ * @var bool
*/
- public $isPostEdit = false;
+ public $is_post_edit = false;
/**
* Unique ID number of the current instance
- *
- * @var integer
+ *
+ * @var integer
*/
public $number = false;
/**
* Unique ID string of the current instance (id_base-number)
- *
+ *
* @var string
*/
public $id = false;
- public $fieldsetId = '';
- public $collectionId = '';
- public $postType;
- public $postTypeKind = 'post';
/**
- * this is field settings (like title, slug etc)
- *
+ * Unique fieldset ID string of the current instance (id_base-number)
+ *
+ * @var string
+ */
+ public $fieldset_id = '';
+
+ /**
+ * Unique collection ID string of the current instance (id_base-number)
+ *
+ * @var string
+ */
+ public $collection_id = '';
+
+ /**
+ * Post type
+ *
+ * @var string
+ */
+ public $post_type;
+
+ /**
+ * Post type kind
+ *
+ * @var string
+ */
+ public $post_type_kind = 'post';
+
+ /**
+ * This is field settings (like title, slug etc)
+ *
* @var array
*/
public $instance = array();
- public $postID = 0;
+
+ /**
+ * Unique post ID string of the current instance (id_base-number)
+ *
+ * @var int
+ */
+ public $post_id = 0;
/**
* Field data for each post
+ *
* @var mixed
*/
public $entry = null;
- public $fieldErrors = array();
+
+ /**
+ * Field errors for each post
+ *
+ * @var array
+ */
+ public $field_errors = array();
/**
* DataLayer to save instances to
*
* @var \jcf\core\DataLayer
*/
- protected $_dL;
+ protected $_dl;
/**
* Constructor
+ *
+ * @param int $id_base ID base.
+ * @param string $title Title.
+ * @param array $field_options Field options.
*/
- public function __construct( $id_base, $title, $field_options = array() )
- {
- $this->idBase = $id_base;
- $this->title = $title;
- $this->fieldOptions = array_merge($this->fieldOptions, $field_options);
+ public function __construct( $id_base, $title, $field_options = array() ) {
+ $this->id_base = $id_base;
+ $this->title = $title;
+ $this->field_options = array_merge( $this->field_options, $field_options );
- // init data layer
- $this->_dL = DataLayerFactory::create();
+ /* init data layer */
+ $this->_dl = DataLayerFactory::create();
}
/**
- * check field compatibility with WP version
+ * Check field compatibility with WP version
+ *
+ * @param string $compatibility Compability.
+ *
+ * @return bool
* @deprecated
*/
- public static function checkCompatibility( $compatibility )
- {
+ public static function check_compatibility( $compatibility ) {
global $wp_version;
$operator = '<';
- if ( strpos($compatibility, '+') ) {
- $compatibility = substr($compatibility, 0, -1);
- $operator = '>=';
- }
- elseif ( strpos($compatibility, '-') ) {
- $compatibility = substr($compatibility, 0, -1);
+ if ( strpos( $compatibility, '+' ) ) {
+ $compatibility = substr( $compatibility, 0, - 1 );
+ $operator = '>=';
+ } elseif ( strpos( $compatibility, '-' ) ) {
+ $compatibility = substr( $compatibility, 0, - 1 );
}
- if ( !version_compare($wp_version, $compatibility, $operator) )
+ if ( ! version_compare( $wp_version, $compatibility, $operator ) ) {
return false;
+ }
+
return true;
}
/**
- * check, that this field is part of collection
+ * Check, that this field is part of collection
*/
- public function isCollectionField()
- {
- if ( !empty($this->collectionId) )
+ public function is_collection_field() {
+ if ( ! empty( $this->collection_id ) ) {
return true;
+ }
+
return false;
}
/**
* Check if this field is created for taxonomy.
*/
- public function isTaxonomyField()
- {
- return ( self::POSTTYPE_KIND_TAXONOMY === $this->postTypeKind );
+ public function is_taxonomy_field() {
+ return ( self::POSTTYPE_KIND_TAXONOMY === $this->post_type_kind );
}
/**
- * set class property $this->fieldsetId
- * @param string $fieldset_id fieldset string ID
+ * Set class property $this->fieldset_id
+ *
+ * @param string $fieldset_id fieldset string ID.
*/
- public function setFieldset( $fieldset_id )
- {
- $this->fieldsetId = $fieldset_id;
+ public function set_fieldset( $fieldset_id ) {
+ $this->fieldset_id = $fieldset_id;
}
/**
- * set class property $this->collectionId
- * @param string $fieldset_id fieldset string ID
+ * Set class property $this->collection_id
+ *
+ * @param string $collection_id fieldset string ID.
*/
- public function setCollection( $collection_id )
- {
- $this->collectionId = $collection_id;
+ public function set_collection( $collection_id ) {
+ $this->collection_id = $collection_id;
}
/**
- * set class propreties "id", "number"
+ * Set class propreties "id", "number"
* load instance and entries for this field
- * @param string $id field id (cosist of id_base + number)
+ *
+ * @param string $id field id (cosist of id_base + number).
*/
- public function setId( $id )
- {
+ public function set_id( $id ) {
$this->id = $id;
- // this is add request. so number is 0
- if ( $this->id == $this->idBase ) {
+ // this is add request. so number is 0.
+ if ( $this->id == $this->id_base ) {
$this->number = 0;
- $this->isNew = true;
- }
- // parse number
+ $this->is_new = true;
+ } // parse number
else {
- $this->number = str_replace($this->idBase . '-', '', $this->id);
+ $this->number = str_replace( $this->id_base . '-', '', $this->id );
- // load instance data
- $fields = $this->_dL->getFields();
- if ( isset($fields[$this->postType][$this->id]) )
- $this->instance = (array) $fields[$this->postType][$this->id];
+ // load instance data.
+ $fields = $this->_dl->get_fields();
+ if ( isset( $fields[ $this->post_type ][ $this->id ] ) ) {
+ $this->instance = (array) $fields[ $this->post_type ][ $this->id ];
+ }
- if ( !empty($this->instance) ) {
- $this->slug = $this->instance['slug'];
- $this->fieldOptions['after_title'] .= '
+ if ( ! empty( $this->instance ) ) {
+ $this->slug = $this->instance['slug'];
+ $this->field_options['after_title'] .= '
';
}
@@ -179,291 +258,306 @@ public function setId( $id )
}
/**
- * setter for slug
- * @param string $slug field slug
+ * Setter for slug
+ *
+ * @param string $slug field slug.
*/
- public function setSlug( $slug )
- {
- $this->slug = $this->validateInstanceSlug($slug);
+ public function set_slug( $slug ) {
+ $this->slug = $this->validate_instance_slug( $slug );
}
/**
- * set post ID and load entry from wp-postmeta
- * @param int $post_ID post ID variable
+ * Set post ID and load entry from wp-postmeta
+ *
+ * @param int $post_id post ID variable.
+ * @param bool $key_from_collection key from collection variable.
*/
- public function setPostID( $post_ID, $key_from_collection = FALSE )
- {
- $this->postID = $post_ID;
+ public function set_post_id( $post_id, $key_from_collection = false ) {
+ $this->post_id = $post_id;
- if ( !empty($this->collectionId) ) {
- // load entry
- if ( !empty($this->slug) ) {
- $fields = $this->_dL->getFields();
- if ( empty($fields[$this->postType][$this->collectionId]) )
+ if ( ! empty( $this->collection_id ) ) {
+ // load entry.
+ if ( ! empty( $this->slug ) ) {
+ $fields = $this->_dl->get_fields();
+ if ( empty( $fields[ $this->post_type ][ $this->collection_id ] ) ) {
return;
+ }
- $collection_slug = $fields[$this->postType][$this->collectionId]['slug'];
- $data = $this->get_meta_data($this->postID, $collection_slug, true);
+ $collection_slug = $fields[ $this->post_type ][ $this->collection_id ]['slug'];
+ $data = $this->get_meta_data( $this->post_id, $collection_slug, true );
- if ( isset($data[$key_from_collection][$this->slug]) ) {
- $this->entry = $data[$key_from_collection][$this->slug];
+ if ( isset( $data[ $key_from_collection ][ $this->slug ] ) ) {
+ $this->entry = $data[ $key_from_collection ][ $this->slug ];
}
}
- }
- else {
- // load entry
- if ( !empty($this->slug) ) {
- $this->entry = $this->get_meta_data($this->postID, $this->slug, true);
+ } else {
+ // load entry.
+ if ( ! empty( $this->slug ) ) {
+ $this->entry = $this->get_meta_data( $this->post_id, $this->slug, true );
}
}
}
/**
- * Get meta data from post or term based on current postTypeKind
+ * Get meta data from post or term based on current post_type_kind
*
- * @param int $object_id Post or Term ID
- * @param string $meta_key Meta data key (identifier)
- * @param bool $single Value is single or not.
+ * @param int $object_id Post or Term ID.
+ * @param string $meta_key Meta data key (identifier).
+ * @param bool $single Value is single or not.
*
* @return mixed|null
*/
- public function get_meta_data($object_id, $meta_key, $single = false)
- {
- if ( self::POSTTYPE_KIND_POST == $this->postTypeKind ) {
- return get_post_meta($object_id, $meta_key, $single);
- } elseif ( self::POSTTYPE_KIND_TAXONOMY == $this->postTypeKind ) {
- return get_term_meta($object_id, $meta_key, $single);
+ public function get_meta_data( $object_id, $meta_key, $single = false ) {
+ if ( self::POSTTYPE_KIND_POST == $this->post_type_kind ) {
+ return get_post_meta( $object_id, $meta_key, $single );
+ } elseif ( self::POSTTYPE_KIND_TAXONOMY == $this->post_type_kind ) {
+ return get_term_meta( $object_id, $meta_key, $single );
} else {
return null;
}
}
-
+
/**
* Set post type
- * @param string $post_type
+ *
+ * @param string $post_type Post type.
*/
- public function setPostType( $post_type )
- {
- $this->postType = $post_type;
- if ( 0 === strpos($this->postType, self::POSTTYPE_KIND_PREFIX_TAXONOMY) ) {
- $this->postTypeKind = self::POSTTYPE_KIND_TAXONOMY;
+ public function set_post_type( $post_type ) {
+ $this->post_type = $post_type;
+ if ( 0 === strpos( $this->post_type, self::POSTTYPE_KIND_PREFIX_TAXONOMY ) ) {
+ $this->post_type_kind = self::POSTTYPE_KIND_TAXONOMY;
} else {
- $this->postTypeKind = self::POSTTYPE_KIND_POST;
+ $this->post_type_kind = self::POSTTYPE_KIND_POST;
}
}
/**
- * generate unique id attribute based on id_base and number
- * @param string $str string to be converted
+ * Generate unique id attribute based on id_base and number
+ *
+ * @param string $str string to be converted.
+ * @param string $delimeter string delimiter.
+ *
* @return string
*/
- public function getFieldId( $str, $delimeter = '-' )
- {
+ public function get_field_id( $str, $delimeter = '-' ) {
/**
- * if is field of collection and itst post edit page create collection field id
+ * If is field of collection and itst post edit page create collection field id.
*/
- $params = array(
- 'post_type' => $this->postType,
- 'field_id' => $this->collectionId,
- 'fieldset_id' => $this->fieldsetId
+ $params = array(
+ 'post_type' => $this->post_type,
+ 'field_id' => $this->collection_id,
+ 'fieldset_id' => $this->fieldset_id,
);
$field_model = new models\Field();
- $field_model->load($params);
+ $field_model->load( $params );
+
+ if ( $this->is_collection_field() && $this->is_post_edit ) {
+ $collection = core\JustFieldFactory::create( $field_model );
- if ( $this->isCollectionField() && $this->isPostEdit ) {
- $collection = core\JustFieldFactory::create($field_model);
- return str_replace('-', $delimeter, 'field' . $delimeter . $collection->idBase . $delimeter . $collection->number . $delimeter
- . \jcf\components\collection\JustField_Collection::$currentCollectionFieldKey . $delimeter . $this->id . $delimeter . $str);
+ return str_replace( '-', $delimeter, 'field' . $delimeter . $collection->id_base . $delimeter . $collection->number . $delimeter
+ . \jcf\components\collection\JustField_Collection::$current_collection_field_key . $delimeter . $this->id . $delimeter . $str );
}
- return 'field' . $delimeter . $this->idBase . $delimeter . $this->number . $delimeter . $str;
+
+ return 'field' . $delimeter . $this->id_base . $delimeter . $this->number . $delimeter . $str;
}
/**
- * generate unique name attribute based on id_base and number
- * @param string $str string to be converted
+ * Generate unique name attribute based on id_base and number
+ *
+ * @param string $str string to be converted.
+ *
* @return string
*/
- public function getFieldName( $str )
- {
+ public function get_field_name( $str ) {
/**
- * if is field of collection and itst post edit page create collection field name
+ * If is field of collection and itst post edit page create collection field name
*/
- $params = array(
- 'post_type' => $this->postType,
- 'field_id' => $this->collectionId,
- 'fieldset_id' => $this->fieldsetId
+ $params = array(
+ 'post_type' => $this->post_type,
+ 'field_id' => $this->collection_id,
+ 'fieldset_id' => $this->fieldset_id,
);
$field_model = new models\Field();
- $field_model->load($params);
+ $field_model->load( $params );
+
+ if ( $this->is_collection_field() && $this->is_post_edit ) {
+ $collection = core\JustFieldFactory::create( $field_model );
- if ( $this->isCollectionField() && $this->isPostEdit ) {
- $collection = core\JustFieldFactory::create($field_model);
- return 'field-' . $collection->idBase . '[' . $collection->number . '][' . \jcf\components\collection\JustField_Collection::$currentCollectionFieldKey . '][' . $this->id . '][' . $str . ']';
+ return 'field-' . $collection->id_base . '[' . $collection->number . '][' . \jcf\components\collection\JustField_Collection::$current_collection_field_key . '][' . $this->id . '][' . $str . ']';
}
- return 'field-' . $this->idBase . '[' . $this->number . '][' . $str . ']';
+
+ return 'field-' . $this->id_base . '[' . $this->number . '][' . $str . ']';
}
/**
- * validates instance. normalize different field values
- * @param array $instance
+ * Validates instance. normalize different field values
+ *
+ * @param array $instance Instance.
*/
- public function validateInstance( & $instance )
- {
+ public function validate_instance( & $instance ) {
if ( $instance['_version'] >= 1.4 ) {
- $instance['slug'] = $this->validateInstanceSlug($instance['slug']);
+ $instance['slug'] = $this->validate_instance_slug( $instance['slug'] );
}
}
/**
- * validate that slug has first underscore
- * @param string $slug
+ * Validate that slug has first underscore
+ *
+ * @param string $slug Slug.
+ *
* @return string
*/
- public function validateInstanceSlug( $slug )
- {
- $slug = trim($slug);
+ public function validate_instance_slug( $slug ) {
+ $slug = trim( $slug );
- if ( !empty($slug) && $slug{0} != '_' && !$this->isCollectionField() ) {
+ if ( ! empty( $slug ) && '_' !== $slug{0} && ! $this->is_collection_field() ) {
$slug = '_' . $slug;
}
+
return $slug;
}
/**
- * get valid value for instance version
- * @param array $instance
+ * Get valid value for instance version
+ *
+ * @param array $instance Instance.
+ *
* @return float
*/
- public function getInstanceVersion( $instance )
- {
- if ( empty($instance['_version']) )
+ public function get_instance_version( $instance ) {
+ if ( empty( $instance['_version'] ) ) {
return 1.34;
- else
+ } else {
return $instance['_version'];
+ }
}
/**
- * method to save field instance to the storage
+ * Method to save field instance to the storage
* call $this->update inside
- * @param array $params for update field
- * @return boolean
+ *
+ * @param array $field_index for update field.
+ * @param array $params for update field.
+ *
+ * @return array
*/
- public function doUpdate( $field_index, $params = null )
- {
- $input = !is_null($params) ? $params : $_POST['field-' . $this->idBase][$this->number];
- // remove all slashed from values
+ public function do_update( $field_index, $params = null ) {
+ $input = ! is_null( $params ) ? $params : $_POST[ 'field-' . $this->id_base ][ $this->number ];
+ // remove all slashed from values.
foreach ( $input as $var => $value ) {
- if ( is_string($value) ) {
- $input[$var] = stripslashes($value);
+ if ( is_string( $value ) ) {
+ $input[ $var ] = stripslashes( $value );
}
}
- // validate: title should be always there
- if ( empty($input['title']) ) {
- return array( 'status' => '0', 'error' => __('Title field is required.', \JustCustomFields::TEXTDOMAIN) );
+ // validate: title should be always there.
+ if ( empty( $input['title'] ) ) {
+ return array( 'status' => '0', 'error' => __( 'Title field is required.', 'jcf' ) );
}
- // get values from real class:
- $instance = $this->update($input, $this->instance);
- $instance['title'] = strip_tags($instance['title']);
- $instance['slug'] = strip_tags($input['slug']);
+ // get values from real class.
+ $instance = $this->update( $input, $this->instance );
+ $instance['title'] = strip_tags( $instance['title'] );
+ $instance['slug'] = strip_tags( $input['slug'] );
$instance['enabled'] = (int) @$input['enabled'];
- if ( $this->idBase == 'inputtext' )
+ if ( $this->id_base === 'inputtext' ) {
$instance['group_title'] = (int) @$input['group_title'];
+ }
- // starting from vers. 1.4 all new fields should be marked with version of the plugin
- if ( $this->isNew ) {
+ // starting from vers. 1.4 all new fields should be marked with version of the plugin.
+ if ( $this->is_new ) {
$instance['_version'] = \JustCustomFields::VERSION;
}
- // for old records: set 1.34 - last version without versioning the fields
- if ( empty($instance['_version']) ) {
+ // for old records: set 1.34 - last version without versioning the fields.
+ if ( empty( $instance['_version'] ) ) {
$instance['_version'] = 1.34;
}
- $instance['_type'] = $this->idBase;
+ $instance['_type'] = $this->id_base;
- // new from version 1.4: validation/normalization
- $this->validateInstance($instance);
+ // new from version 1.4: validation/normalization.
+ $this->validate_instance( $instance );
// check for errors
- // IMPORTANT: experimental function
- if ( !empty($this->fieldErrors) ) {
- $errors = implode('\n', $this->fieldErrors);
+ // IMPORTANT: experimental function.
+ if ( ! empty( $this->field_errors ) ) {
+ $errors = implode( '\n', $this->field_errors );
+
return array( 'status' => '0', 'error' => $errors );
}
- if ( $this->isNew ) {
+ if ( $this->is_new ) {
$this->number = $field_index;
- $this->id = $this->idBase . '-' . $this->number;
+ $this->id = $this->id_base . '-' . $this->number;
}
- // check slug field
- if ( empty($instance['slug']) ) {
- $instance['slug'] = '_field_' . $this->idBase . '__' . $this->number;
+ // check slug field.
+ if ( empty( $instance['slug'] ) ) {
+ $instance['slug'] = '_field_' . $this->id_base . '__' . $this->number;
}
- $fields = $this->_dL->getFields();
+ $fields = $this->_dl->get_fields();
- if ( !$this->isCollectionField() ) {
- // update fieldset
- $fieldsets = $this->_dL->getFieldsets();
- $fieldsets[$this->postType][$this->fieldsetId]['fields'][$this->id] = $instance['enabled'];
- $this->_dL->setFieldsets($fieldsets);
- $this->_dL->saveFieldsetsData();
+ if ( ! $this->is_collection_field() ) {
+ // update fieldset.
+ $fieldsets = $this->_dl->get_fieldsets();
+ $fieldsets[ $this->post_type ][ $this->fieldset_id ]['fields'][ $this->id ] = $instance['enabled'];
+ $this->_dl->set_fieldsets( $fieldsets );
+ $this->_dl->save_fieldsets_data();
- $fields[$this->postType][$this->id] = $instance;
- }
- else {
+ $fields[ $this->post_type ][ $this->id ] = $instance;
+ } else {
$instance['field_width'] = $input['field_width'];
- if ( isset($input['group_title']) )
+ if ( isset( $input['group_title'] ) ) {
$instance['group_title'] = true;
+ }
- $fields[$this->postType][$this->collectionId]['fields'][$this->id] = $instance;
+ $fields[ $this->post_type ][ $this->collection_id ]['fields'][ $this->id ] = $instance;
}
- $this->_dL->setFields($fields);
- if ( !$this->_dL->saveFieldsData() ) {
+ $this->_dl->set_fields( $fields );
+ if ( ! $this->_dl->save_fields_data() ) {
return array(
'status' => 0,
- 'error' => __('Unable to write changes to storage.', \JustCustomFields::TEXTDOMAIN)
+ 'error' => __( 'Unable to write changes to storage.', 'jcf' ),
);
}
- // return status
+ // return status.
$res = array(
- 'status' => '1',
- 'id' => $this->id,
- 'id_base' => $this->idBase,
- 'fieldset_id' => $this->fieldsetId,
- 'collection_id' => $this->collectionId,
- 'is_new' => $this->isNew,
- 'instance' => $instance
+ 'status' => '1',
+ 'id' => $this->id,
+ 'id_base' => $this->id_base,
+ 'fieldset_id' => $this->fieldset_id,
+ 'collection_id' => $this->collection_id,
+ 'is_new' => $this->is_new,
+ 'instance' => $instance,
);
+
return $res;
}
/**
- * method to delete field from the storage
+ * Method to delete field from the storage
+ *
* @return boolean
*/
- public function doDelete()
- {
- $fields = $this->_dL->getFields();
+ public function do_delete() {
+ $fields = $this->_dl->get_fields();
- if ( !empty($this->collectionId) ) {
- unset($fields[$this->postType][$this->collectionId]['fields'][$this->id]);
- }
- else {
- $fieldsets = $this->_dL->getFieldsets();
- unset($fieldsets[$this->postType][$this->fieldsetId]['fields'][$this->id]);
- unset($fields[$this->postType][$this->id]);
+ if ( ! empty( $this->collection_id ) ) {
+ unset( $fields[ $this->post_type ][ $this->collection_id ]['fields'][ $this->id ] );
+ } else {
+ $fieldsets = $this->_dl->get_fieldsets();
+ unset( $fieldsets[ $this->post_type ][ $this->fieldset_id ]['fields'][ $this->id ] );
+ unset( $fields[ $this->post_type ][ $this->id ] );
- $this->_dL->setFieldsets($fieldsets);
- $this->_dL->saveFieldsetsData();
+ $this->_dl->set_fieldsets( $fieldsets );
+ $this->_dl->save_fieldsets_data();
}
- $this->_dL->setFields($fields);
- if ( !$this->_dL->saveFieldsData() ) {
+ $this->_dl->set_fields( $fields );
+ if ( ! $this->_dl->save_fields_data() ) {
return false;
}
@@ -471,77 +565,74 @@ public function doDelete()
}
/**
- * method to save data from edit post page to postmeta
+ * Method to save data from edit post page to postmeta
* call $this->save()
*
* @return boolean;
*/
- public function doSave()
- {
- // check that number and post_ID is set
- if ( empty($this->postID) || empty($this->number) )
+ public function do_save() {
+ // check that number and post_ID is set.
+ if ( empty( $this->post_id ) || empty( $this->number ) ) {
return false;
+ }
- // check that we have data in POST
- if ( $this->idBase != 'checkbox' && (
- empty($_POST['field-' . $this->idBase][$this->number]) ||
- !is_array($_POST['field-' . $this->idBase][$this->number])
- )
+ // check that we have data in POST.
+ if ( 'checkbox' !== $this->id_base && (
+ empty( $_POST[ 'field-' . $this->id_base ][ $this->number ] ) ||
+ ! is_array( $_POST[ 'field-' . $this->id_base ][ $this->number ] )
+ )
) {
return false;
}
- $input = @$_POST['field-' . $this->idBase][$this->number];
+ $input = @$_POST[ 'field-' . $this->id_base ][ $this->number ];
- // get real values
- $values = $this->save($input);
- // save to post meta
- $this->update_meta_data($this->postID, $this->slug, $values);
+ // get real values.
+ $values = $this->save( $input );
+ // save to post meta.
+ $this->update_meta_data( $this->post_id, $this->slug, $values );
return true;
}
/**
- * Update meta data for post or term based on current postTypeKind
+ * Update meta data for post or term based on current post_type_kind
*
- * @param int $object_id Post or Term ID
- * @param string $meta_key Meta data key (identifier)
+ * @param int $object_id Post or Term ID.
+ * @param string $meta_key Meta data key (identifier).
* @param mixed $meta_value Meta value to be saved.
*
* @return mixed|null
*/
- public function update_meta_data($object_id, $meta_key, $meta_value)
- {
- if ( self::POSTTYPE_KIND_POST == $this->postTypeKind ) {
- return update_post_meta($object_id, $meta_key, $meta_value);
- } elseif ( self::POSTTYPE_KIND_TAXONOMY == $this->postTypeKind ) {
- return update_term_meta($object_id, $meta_key, $meta_value);
+ public function update_meta_data( $object_id, $meta_key, $meta_value ) {
+ if ( self::POSTTYPE_KIND_POST == $this->post_type_kind ) {
+ return update_post_meta( $object_id, $meta_key, $meta_value );
+ } elseif ( self::POSTTYPE_KIND_TAXONOMY == $this->post_type_kind ) {
+ return update_term_meta( $object_id, $meta_key, $meta_value );
} else {
return null;
}
}
-
+
/**
- * method that call $this->add_js to enqueue scripts in head section
+ * Method that call $this->add_js to enqueue scripts in head section
* do this only on post edit page and if at least one field is exists.
* do this only once
*/
- public function doAddJs()
- {
- if ( method_exists($this, 'addJs') ) {
- $this->addJs();
+ public function do_add_js() {
+ if ( method_exists( $this, 'add_js' ) ) {
+ $this->add_js();
}
}
/**
- * method that call $this->add_css to enqueue styles in head section
+ * Method that call $this->add_css to enqueue styles in head section
* do this only on post edit page and if at least one field is exists.
* do this only once
*/
- public function doAddCss()
- {
- if ( method_exists($this, 'addCss') ) {
- $this->addCss();
+ public function do_add_css() {
+ if ( method_exists( $this, 'add_css' ) ) {
+ $this->add_css();
}
}
@@ -549,12 +640,9 @@ public function doAddCss()
* Echo the field post edit form.
*
* Subclasses should over-ride this function to generate their field code.
- *
- * @param array $args Field options data
*/
- public function field()
- {
- die('function cf_Field::field() must be over-ridden in a sub-class.');
+ public function field() {
+ die( 'function cf_Field::field() must be over-ridden in a sub-class.' );
}
/**
@@ -562,11 +650,10 @@ public function field()
*
* Subclasses should over-ride this function to generate their field code.
*
- * @param array $values Form submitted values
+ * @param array $values Form submitted values.
*/
- public function save( $values )
- {
- die('function cf_Field::save() must be over-ridden in a sub-class.');
+ public function save( $values ) {
+ die( 'function cf_Field::save() must be over-ridden in a sub-class.' );
}
/**
@@ -576,93 +663,94 @@ public function save( $values )
* The newly calculated value of $instance should be returned.
* If "false" is returned, the instance won't be saved/updated.
*
- * @param array $new_instance New settings for this instance as input by the user via form()
- * @param array $old_instance Old settings for this instance
+ * @param array $new_instance New settings for this instance as input by the user via form().
+ * @param array $old_instance Old settings for this instance.
+ *
* @return array Settings to save or bool false to cancel saving
*/
- public function update( $new_instance, $old_instance )
- {
+ public function update( $new_instance, $old_instance ) {
return $new_instance;
}
/**
* Echo the settings update form
*
- * @param array $instance Current settings
* @return string
*/
- public function form()
- {
- echo '
' . __('There are no options for this field.', \JustCustomFields::TEXTDOMAIN) . '
';
+ public function form() {
+ echo '
' . esc_html__( 'There are no options for this field.', 'jcf' ) . '
';
+
return 'noform';
}
/**
* Print shortcode
- *
- * @param array $args shortcode attributes
+ *
+ * @param array $args shortcode attributes.
+ *
* @return string
*/
- public function doShortcode( $args )
- {
- $args = array_merge(array(
- 'id' => '',
- 'class' => '',
- 'field' => '',
+ public function do_shortcode( $args ) {
+ $args = array_merge( array(
+ 'id' => '',
+ 'class' => '',
+ 'field' => '',
'post_id' => '',
- 'label' => false,
- ), $args);
+ 'label' => false,
+ ), $args );
$class_names = array(
- "jcf-value",
- "jcf-value-{$this->idBase}",
- "jcf-value-{$this->idBase}-{$this->slug}",
+ 'jcf-value',
+ "jcf-value-{$this->id_base}",
+ "jcf-value-{$this->id_base}-{$this->slug}",
);
- if ( !empty($args['class']) ) {
+ if ( ! empty( $args['class'] ) ) {
$class_names[] = $args['class'];
}
- $class = implode(' ', $class_names);
- $id = "jcf-value-{$this->id}";
+ $class = implode( ' ', $class_names );
+ $id = "jcf-value-{$this->id}";
- if ( !empty($args['id']) ) {
+ if ( ! empty( $args['id'] ) ) {
$id = $args['id'];
}
- $sc = '
';
+ $sc = '
';
$args['before_label'] = '
';
- $args['after_label'] = '
';
+ $args['after_label'] = '
';
$args['before_value'] = '
';
- $args['after_value'] = '
';
+ $args['after_value'] = '
';
- if ( !empty($args['label']) )
- $sc .= $this->shortcodeLabel($args);
+ if ( ! empty( $args['label'] ) ) {
+ $sc .= $this->shortcode_label( $args );
+ }
- $sc .= $this->shortcodeValue($args);
+ $sc .= $this->shortcode_value( $args );
$sc .= '
';
+
return $sc;
}
/**
* Print field label inside shortcode call
- *
- * @param array $args shortcode args
+ *
+ * @param array $args shortcode args.
+ *
* @return string
*/
- public function shortcodeLabel( $args )
- {
- return $args['before_label'] . esc_html($this->instance['title']) . $args['after_label'];
+ public function shortcode_label( $args ) {
+ return $args['before_label'] . esc_html( $this->instance['title'] ) . $args['after_label'];
}
/**
* Print fields values from shortcode
- *
- * @param array $args shortcode args
+ *
+ * @param array $args shortcode args.
+ *
* @return string
*/
- public function shortcodeValue( $args )
- {
- return $args['before_value'] . esc_html($this->entry) . $args['after_value'];
+ public function shortcode_value( $args ) {
+ return $args['before_value'] . esc_html( $this->entry ) . $args['after_value'];
}
}
diff --git a/core/JustFieldFactory.php b/core/JustFieldFactory.php
index 430f24f..f6a5e4b 100644
--- a/core/JustFieldFactory.php
+++ b/core/JustFieldFactory.php
@@ -7,42 +7,41 @@
*
* Creates JustField child object based on loaded Field model
*/
-class JustFieldFactory
-{
+class JustFieldFactory {
/**
* Create Just_Field object of the required type
- *
- * @param \jcf\models\Field $field
+ *
+ * @param \jcf\models\Field $field Field.
+ *
* @return \jcf\core\JustField
*/
- public static function create( \jcf\models\Field $field )
- {
- // $field_mixed can be real field id or only id_base
- $field_mixed = !empty($field->field_id) ? $field->field_id : $field->field_type;
- $id_base = preg_replace('/\-([0-9]+)/', '', $field_mixed);
+ public static function create( \jcf\models\Field $field ) {
+ // $field_mixed can be real field id or only id_base.
+ $field_mixed = ! empty( $field->field_id ) ? $field->field_id : $field->field_type;
+ $id_base = preg_replace( '/\-([0-9]+)/', '', $field_mixed );
- $jcf = \JustCustomFields::run();
- $field_info = $jcf->getFieldInfo($id_base);
+ $jcf = \JustCustomFields::run();
+ $field_info = $jcf->get_field_info( $id_base );
- if ( empty($field_info['class']) || !class_exists($field_info['class']) ) {
+ if ( empty( $field_info['class'] ) || ! class_exists( $field_info['class'] ) ) {
return null;
}
$model = new $field_info['class']();
- $model->setPostType($field->post_type);
- $model->setFieldset($field->fieldset_id);
- $model->setCollection($field->collection_id);
- $model->setId($field_mixed);
+ $model->set_post_type( $field->post_type );
+ $model->set_fieldset( $field->fieldset_id );
+ $model->set_collection( $field->collection_id );
+ $model->set_id( $field_mixed );
- if ( !$model->isNew && $field->collection_id ) {
+ if ( ! $model->is_new && $field->collection_id ) {
$collection = new \jcf\components\collection\JustField_Collection();
- $collection->setPostType($field->post_type);
- $collection->setFieldset($field->fieldset_id);
- $collection->setId($field->collection_id);
+ $collection->set_post_type( $field->post_type );
+ $collection->set_fieldset( $field->fieldset_id );
+ $collection->set_id( $field->collection_id );
- $field_instance = $collection->instance['fields'][$field_mixed];
- $model->setSlug($field_instance['slug']);
+ $field_instance = $collection->instance['fields'][ $field_mixed ];
+ $model->set_slug( $field_instance['slug'] );
$model->instance = $field_instance;
}
@@ -50,15 +49,15 @@ public static function create( \jcf\models\Field $field )
}
/**
- * get next index for save new instance
- * because of ability to import fields now, we can't use DB to save AI.
+ * Get next index for save new instance
+ * because of ability to import fields now, we can't use DB to save AI.
* we will use timestamp for this
*
- * @param string $id_base DEPRECATED!
+ * @param string $id_base DEPRECATED!.
+ *
* @return integer
*/
- public static function createFieldIndex( $id_base )
- {
+ public static function create_field_index( $id_base ) {
return time();
}
diff --git a/core/Migration.php b/core/Migration.php
index e81f532..b835e22 100644
--- a/core/Migration.php
+++ b/core/Migration.php
@@ -11,8 +11,7 @@
*
* @package jcf\core
*/
-abstract class Migration
-{
+abstract class Migration {
const FIELDS_KEY = 'fields';
const FIELDSETS_KEY = 'fieldsets';
@@ -20,26 +19,36 @@ abstract class Migration
const MODE_UPDATE = 'update';
/**
+ * Data
+ *
* @var array
*/
protected $data;
/**
+ * Mode
+ *
* @var string test|update
*/
protected $mode;
/**
+ * Updated
+ *
* @var boolean
*/
protected $updated;
/**
+ * Data Source
+ *
* @var string
*/
protected $_data_source;
/**
+ * Network Mode
+ *
* @var string
*/
protected $_network_mode;
@@ -49,10 +58,9 @@ abstract class Migration
* Migration constructor.
* Init main settings, which were similar to all versions
*/
- public function __construct()
- {
- $this->_data_source = Settings::getDataSourceType();
- $this->_network_mode = Settings::getNetworkMode();
+ public function __construct() {
+ $this->_data_source = Settings::get_data_source_type();
+ $this->_network_mode = Settings::get_network_mode();
}
/**
@@ -60,7 +68,7 @@ public function __construct()
*
* @return void
*/
- abstract protected function readData();
+ abstract protected function read_data();
/**
* Test data compatibility with newer version
@@ -79,17 +87,17 @@ abstract protected function update();
/**
* Function to be called to remove old settings after update
*/
- protected function cleanup(){}
+ protected function cleanup() {
+ }
/**
* Compare current active data source with parameter
*
- * @param string $data_source
+ * @param string $data_source Data source.
*
* @return bool
*/
- public function isDataSource( $data_source )
- {
+ public function is_data_source( $data_source ) {
return $this->_data_source === $data_source;
}
@@ -98,21 +106,19 @@ public function isDataSource( $data_source )
*
* @return bool
*/
- public function isTestMode()
- {
- return $this->mode !== self::MODE_UPDATE;
+ public function is_test_mode() {
+ return self::MODE_UPDATE !== $this->mode;
}
/**
* Run compatibility data test
*
- * @param array|null $data
+ * @param array|null $data Data.
*
* @return array
*/
- public function runTest( $data )
- {
- $this->setData($data);
+ public function run_test( $data ) {
+ $this->set_data( $data );
return $this->test();
}
@@ -120,15 +126,14 @@ public function runTest( $data )
/**
* Update data to match new format
*
- * @param array|null $data
- * @param string $mode
+ * @param array|null $data Data.
+ * @param string $mode Mode.
*
* @return array
*/
- public function runUpdate( $data, $mode = 'test' )
- {
- $this->setData($data);
- $this->mode = ($mode == self::MODE_UPDATE) ? self::MODE_UPDATE : self::MODE_TEST;
+ public function run_update( $data, $mode = 'test' ) {
+ $this->set_data( $data );
+ $this->mode = ( self::MODE_UPDATE === $mode ) ? self::MODE_UPDATE : self::MODE_TEST;
$this->updated = $this->update();
@@ -138,8 +143,7 @@ public function runUpdate( $data, $mode = 'test' )
/**
* Run clean up of old data after update
*/
- public function runCleanup()
- {
+ public function run_cleanup() {
if ( $this->updated ) {
$this->cleanup();
}
@@ -148,45 +152,40 @@ public function runCleanup()
/**
* Set data from input or read data from settings if input parameter is empty
*
- * @param array|null $data
- *
- * @return array
+ * @param array|null $data Data.
*/
- public function setData( $data )
- {
- if ( ! empty($data) ) {
+ public function set_data( $data ) {
+ if ( ! empty( $data ) ) {
$this->data = $data;
} else {
- $this->readData();
+ $this->read_data();
}
}
/**
* Read DB option based on settings mode
*
- * @param string $key
+ * @param string $key Key.
*
* @return mixed
*/
- public function readDB( $key )
- {
- return ($this->_network_mode == Settings::CONF_MS_NETWORK) ? get_site_option($key) : get_option($key);
+ public function read_db( $key ) {
+ return ( Settings::CONF_MS_NETWORK === $this->_network_mode ) ? get_site_option( $key ) : get_option( $key );
}
/**
* Prepend path with root folder based on FS setting and read file
*
- * @param string $path
+ * @param string $path Path.
*
* @return string
*/
- public function readFS( $path )
- {
- $root_folder = $this->getFilesRoot();
+ public function read_fs( $path ) {
+ $root_folder = $this->get_files_root();
- $file = $root_folder . '/' . ltrim($path, '/');
- if ( is_file($file) ) {
- return file_get_contents($file);
+ $file = $root_folder . '/' . ltrim( $path, '/' );
+ if ( is_file( $file ) ) {
+ return file_get_contents( $file );
}
return null;
@@ -195,13 +194,12 @@ public function readFS( $path )
/**
* Read DB option based on settings mode
*
- * @param string $key
+ * @param string $key Key.
*
* @return mixed
*/
- public function cleanDB( $key )
- {
- return ($this->_network_mode == Settings::CONF_MS_NETWORK) ? delete_site_option($key) : delete_option($key);
+ public function clean_db( $key ) {
+ return ( Settings::CONF_MS_NETWORK === $this->_network_mode ) ? delete_site_option( $key ) : delete_option( $key );
}
/**
@@ -209,9 +207,9 @@ public function cleanDB( $key )
*
* @return string
*/
- public function getFilesRoot()
- {
- $root_folder = ($this->_data_source == Settings::CONF_SOURCE_FS_THEME) ? get_stylesheet_directory() : WP_CONTENT_DIR;
+ public function get_files_root() {
+ $root_folder = ( Settings::CONF_SOURCE_FS_THEME === $this->_data_source ) ? get_stylesheet_directory() : WP_CONTENT_DIR;
+
return $root_folder;
}
@@ -219,42 +217,40 @@ public function getFilesRoot()
/**
* Find postmeta by $old_slug, convert it with $formatter and save into $new_slug
*
- * @param string $post_type
- * @param string $old_slug
- * @param string $new_slug
- * @param array $formatter class object and method name
- * @return boolean
+ * @param string $post_type Post type.
+ * @param string $old_slug Old slug.
+ * @param string $new_slug New slug.
+ * @param array $formatter class object and method name.
*/
- protected function importPostmeta($post_type, $old_slug, $new_slug, $formatter)
- {
+ protected function import_postmeta( $post_type, $old_slug, $new_slug, $formatter ) {
global $wpdb;
$blog_ids = array( get_current_blog_id() );
if ( is_multisite() && (
- ($this->isDataSource(Settings::CONF_SOURCE_DB) && Settings::CONF_MS_NETWORK == Settings::getNetworkMode())
- || $this->isDataSource(Settings::CONF_SOURCE_FS_GLOBAL)
+ ( $this->is_data_source( Settings::CONF_SOURCE_DB ) && Settings::CONF_MS_NETWORK == Settings::get_network_mode() )
+ || $this->is_data_source( Settings::CONF_SOURCE_FS_GLOBAL )
)
) {
- // TODO: test multisite mode
- $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
+ // TODO: test multisite mode.
+ $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
}
- foreach ($blog_ids as $blog_id) {
- is_multisite() && switch_to_blog($blog_id);
+ foreach ( $blog_ids as $blog_id ) {
+ is_multisite() && switch_to_blog( $blog_id );
- // from and where part to be prepared
- $from_where = $wpdb->prepare("FROM $wpdb->postmeta as pm INNER JOIN $wpdb->posts as p ON p.id = pm.post_id WHERE meta_key = %s", $old_slug);
+ // from and where part to be prepared.
+ $from_where = $wpdb->prepare( "FROM $wpdb->postmeta as pm INNER JOIN $wpdb->posts as p ON p.id = pm.post_id WHERE meta_key = %s", $old_slug );
- // add batch in 100 rows to prevent memorey overload
- $start = 0;
+ // add batch in 100 rows to prevent memorey overload.
+ $start = 0;
$per_page = 1000;
- $count = $wpdb->get_var("SELECT count(meta_id) $from_where");
+ $count = $wpdb->get_var( "SELECT count(meta_id) $from_where" );
- while($start < $count) {
- $postmeta_rows = $wpdb->get_results("SELECT meta_id, post_id, meta_key, meta_value $from_where LIMIT $start, $per_page");
+ while ( $start < $count ) {
+ $postmeta_rows = $wpdb->get_results( "SELECT meta_id, post_id, meta_key, meta_value $from_where LIMIT $start, $per_page" );
- if ( !empty($postmeta_rows) ) {
- // update meta one by one
+ if ( ! empty( $postmeta_rows ) ) {
+ // update meta one by one.
foreach ( $postmeta_rows as $postmeta ) {
$value = call_user_func_array( $formatter, array( $postmeta ) );
update_post_meta( $postmeta->post_id, $new_slug, $value );
@@ -263,7 +259,6 @@ protected function importPostmeta($post_type, $old_slug, $new_slug, $formatter)
$start += $per_page;
}
-
}
is_multisite() && restore_current_blog();
diff --git a/core/Model.php b/core/Model.php
index 0535888..cfcc6e0 100755
--- a/core/Model.php
+++ b/core/Model.php
@@ -5,35 +5,41 @@
/**
* Main Model
*/
-class Model
-{
+class Model {
/**
+ * Errors
+ *
* @var array
*/
protected $_errors;
/**
+ * Messages
+ *
* @var array
*/
protected $_messages;
/**
+ * Message templates
+ *
* @var array
*/
- protected $_msgTpls = null;
+ protected $_msg_tpls = null;
/**
+ * Data layers
+ *
* @var \jcf\models\DataLayer
*/
- protected $_dL;
+ protected $_dl;
/**
* Model constructor.
* generate DataLayer object (file system or DB settings storage)
*/
- public function __construct()
- {
- $this->_dL = DataLayerFactory::create();
+ public function __construct() {
+ $this->_dl = DataLayerFactory::create();
}
/**
@@ -42,90 +48,104 @@ public function __construct()
*
* @return array
*/
- public function messageTemplates()
- {
+ public function message_templates() {
return array();
}
/**
* Set errors
- * @param string $error
+ *
+ * @param string $error Error.
*/
- public function addError( $error )
- {
- if ( is_null($this->_msgTpls) ) $this->_msgTpls = $this->messageTemplates();
+ public function add_error( $error ) {
+ if ( is_null( $this->_msg_tpls ) ) {
+ $this->_msg_tpls = $this->message_templates();
+ }
- if ( isset($this->_msgTpls[$error]) ) $error = $this->_msgTpls[$error];
+ if ( isset( $this->_msg_tpls[ $error ] ) ) {
+ $error = $this->_msg_tpls[ $error ];
+ }
$this->_errors[] = $error;
- add_action('jcf_print_admin_notice', array( $this, 'printMessages' ));
+ add_action( 'jcf_print_admin_notice', array( $this, 'print_messages' ) );
}
/**
* Set messages
- * @param string $message
+ *
+ * @param string $message Message.
*/
- public function addMessage( $message )
- {
- if ( is_null($this->_msgTpls) ) $this->_msgTpls = $this->messageTemplates();
+ public function add_message( $message ) {
+ if ( is_null( $this->_msg_tpls ) ) {
+ $this->_msg_tpls = $this->message_templates();
+ }
- if ( isset($this->_msgTpls[$message]) ) $message = $this->_msgTpls[$message];
+ if ( isset( $this->_msg_tpls[ $message ] ) ) {
+ $message = $this->_msg_tpls[ $message ];
+ }
$this->_messages[] = $message;
- add_action('jcf_print_admin_notice', array( $this, 'printMessages' ));
+ add_action( 'jcf_print_admin_notice', array( $this, 'print_messages' ) );
}
- public function getErrors()
- {
+ /**
+ * Get errors
+ */
+ public function get_errors() {
return $this->_errors;
}
/**
* Check errors
*/
- public function hasErrors()
- {
- return !empty($this->_errors);
+ public function has_errors() {
+ return ! empty( $this->_errors );
}
/**
- * Render notices
- * @param array $args
+ * Render notices
+ *
+ * @param array $args Args.
+ *
* @return html
*/
- public function printMessages( $args = array() )
- {
- if ( empty($this->_messages) && empty($this->_errors) )
+ public function print_messages( $args = array() ) {
+ if ( empty( $this->_messages ) && empty( $this->_errors ) ) {
return;
+ }
global $wp_version;
- include( JCF_ROOT . '/views/_notices.php');
+ include( JCF_ROOT . '/views/_notices.php' );
}
/**
* Set request params
- * @param array $params
+ *
+ * @param array $params Params.
+ *
* @return boolean
*/
- public function load( $params )
- {
- if ( !empty($params) ) {
- $this->setAttributes($params);
+ public function load( $params ) {
+ if ( ! empty( $params ) ) {
+ $this->set_attributes( $params );
+
return true;
}
+
return false;
}
/**
* Set attributes to model
- * @param type $params
+ *
+ * @param type $params Params.
*/
- public function setAttributes( $params )
- {
- $self = get_class($this);
+ public function set_attributes( $params ) {
+ $self = get_class( $this );
foreach ( $params as $key => $value ) {
- if ( property_exists($self, $key) )
- $this->$key = is_array($value) ? $value : strip_tags(trim($value));
+ if ( property_exists( $self, $key ) ) {
+ $this->$key = is_array( $value ) ? $value : strip_tags( trim( $value ) );
+ }
}
}
@@ -134,8 +154,7 @@ public function setAttributes( $params )
*
* @return float
*/
- public function getStorageVersion()
- {
- return $this->_dL->getStorageVersion();
+ public function get_storage_version() {
+ return $this->_dl->get_storage_version();
}
}
diff --git a/core/PluginLoader.php b/core/PluginLoader.php
index 4b32c46..b5b2a5b 100644
--- a/core/PluginLoader.php
+++ b/core/PluginLoader.php
@@ -1,4 +1,5 @@
_dL = DataLayerFactory::create();
+ public function __construct() {
+ $this->_dl = DataLayerFactory::create();
}
/**
@@ -30,22 +32,23 @@ public function __construct()
*
* @return bool
*/
- public function checkMigrationsAvailable()
- {
- $version = $this->getStorageVersion();
+ public function check_migrations_available() {
+ $version = $this->get_storage_version();
+
+ // if we can't define version at all - it seems to be a new installation. just write current version.
+ if ( empty( $version ) ) {
+ $this->_dl->save_storage_version();
- // if we can't define version at all - it seems to be a new installation. just write current version
- if ( empty($version) ) {
- $this->_dL->saveStorageVersion();
return false;
}
- if ( version_compare( $version, \JustCustomFields::VERSION, '<') ) {
- define('JCF_MIGRATE_MODE', true);
- // print notice if we're not on migrate page
- if (empty($_GET['page']) || $_GET['page'] != 'jcf_upgrade') {
- add_action( 'admin_notices', array('\jcf\models\Migrate', 'adminUpgradeNotice') );
+ if ( version_compare( $version, \JustCustomFields::VERSION, '<' ) ) {
+ define( 'JCF_MIGRATE_MODE', true );
+ // print notice if we're not on migrate page.
+ if ( empty( $_GET['page'] ) || 'jcf_upgrade' !== $_GET['page'] ) {
+ add_action( 'admin_notices', array( '\jcf\models\Migrate', 'adminUpgradeNotice' ) );
}
+
return true;
}
@@ -58,9 +61,8 @@ public function checkMigrationsAvailable()
*
* @return array|bool|int|mixed
*/
- public function getStorageVersion()
- {
- if ( ! $version = $this->_dL->getStorageVersion() ) {
+ public function get_storage_version() {
+ if ( ! $version = $this->_dl->get_storage_version() ) {
$version = Migrate::guessVersion();
}
diff --git a/core/Singleton.php b/core/Singleton.php
index ac45eb5..a02744b 100755
--- a/core/Singleton.php
+++ b/core/Singleton.php
@@ -2,10 +2,14 @@
namespace jcf\core;
-class Singleton
-{
+/**
+ * Singleton
+ */
+class Singleton {
/**
- * Refers to a single instance of this class.
+ * Refers to a single instance of this class.
+ *
+ * @var $instance
*/
protected static $instance = null;
@@ -14,8 +18,7 @@ class Singleton
*
* @return Singleton A single instance of this class.
*/
- public static function getInstance()
- {
+ public static function get_instance() {
if ( null === static::$instance ) {
static::$instance = new static();
}
@@ -25,30 +28,27 @@ public static function getInstance()
/**
* Alias for creating object of *Singleton* pattern
- *
+ *
* @return Singleton A single instance of this class.
*/
- public static function run()
- {
- return static::getInstance();
+ public static function run() {
+ return static::get_instance();
}
/**
* Protected constructor to prevent creating a new instance of the
* *Singleton* via the `new` operator from outside of this class.
*/
- protected function __construct()
- {
+ protected function __construct() {
}
/**
* Private clone method to prevent cloning of the instance of the
* *Singleton* instance.
- *
+ *
* @return void
*/
- private function __clone()
- {
+ private function __clone() {
}
/**
@@ -57,8 +57,7 @@ private function __clone()
*
* @return void
*/
- private function __wakeup()
- {
+ private function __wakeup() {
}
}
diff --git a/functions/helpers.php b/functions/helpers.php
index ea10e7a..49e9415 100755
--- a/functions/helpers.php
+++ b/functions/helpers.php
@@ -1,11 +1,21 @@
$mixed ); echo( '' . htmlentities(print_r($print, 1)) . ' ' );
- if ( $stop == 1 )
+ $ar = debug_backtrace();
+ $key = pathinfo( $ar[0]['file'] );
+ $key = $key['basename'] . ':' . $ar[0]['line'];
+ $print = array( $key => $mixed );
+ echo( '' . htmlentities( print_r( $print, 1 ) ) . ' ' );
+ if ( 1 === $stop ) {
exit();
+ }
}
}
@@ -13,53 +23,59 @@ function pa( $mixed, $stop = false ) {
* Alias for plugins_url with pre-defined second parameter
* Mostly used to set paths for assets
*
- * @param string $path asset or callback path
+ * @param string $path asset or callback path.
+ *
* @return string
*/
function jcf_plugin_url( $path ) {
- return plugins_url($path, dirname(__FILE__));
+ return plugins_url( $path, dirname( __FILE__ ) );
}
/**
- * get registered post types
- * @param string $format
- * @return string
+ * Get registered post types
+ *
+ * @param string $format Format.
+ *
+ * @return string
*/
function jcf_get_post_types( $format = 'single' ) {
- $all_post_types = get_post_types(array( 'show_ui' => true ), 'object');
+ $all_post_types = get_post_types( array( 'show_ui' => true ), 'object' );
$post_types = array();
foreach ( $all_post_types as $key => $val ) {
- //we should exclude 'revision' and 'nav menu items'
- if ( $val == 'revision' || $val == 'nav_menu_item' )
+ // we should exclude 'revision' and 'nav menu items'.
+ if ( 'revision' === $val || 'nav_menu_item' === $val ) {
continue;
+ }
- $post_types[$key] = $val;
+ $post_types[ $key ] = $val;
}
- if ( isset($post_types['attachment']) ) {
- unset($post_types['attachment']);
+ if ( isset( $post_types['attachment'] ) ) {
+ unset( $post_types['attachment'] );
}
return $post_types;
}
/**
- * get registered taxonomies
- * @param string $format
+ * Get registered taxonomies
+ *
+ * @param string $format Format.
+ *
* @return string
*/
function jcf_get_taxonomies( $format = 'names' ) {
- $all_taxonomies = get_taxonomies(array( 'show_ui' => true, 'public' => true ), $format);
+ $all_taxonomies = get_taxonomies( array( 'show_ui' => true, 'public' => true ), $format );
$taxonomies = array();
foreach ( $all_taxonomies as $key => $val ) {
- $taxonomies[\jcf\core\JustField::POSTTYPE_KIND_PREFIX_TAXONOMY . $key] = $val;
+ $taxonomies[ \jcf\core\JustField::POSTTYPE_KIND_PREFIX_TAXONOMY . $key ] = $val;
}
return $taxonomies;
@@ -68,28 +84,29 @@ function jcf_get_taxonomies( $format = 'names' ) {
/**
* Find the correct post type icon name
*
- * @param array|object $post_type object
+ * @param array|object $post_type object.
+ *
* @return string
*/
function jcf_get_post_type_icon( $post_type ) {
- if ( is_a($post_type, '\WP_Post_Type') ) {
+ if ( is_a( $post_type, '\WP_Post_Type' ) ) {
$icon = $post_type->menu_icon;
- } elseif ( is_a($post_type, '\WP_Taxonomy') ) {
- $icon = $post_type->hierarchical? 'dashicons-category' : 'dashicons-tag';
+ } elseif ( is_a( $post_type, '\WP_Taxonomy' ) ) {
+ $icon = $post_type->hierarchical ? 'dashicons-category' : 'dashicons-tag';
}
- $post_type = (array)$post_type;
+ $post_type = (array) $post_type;
$standard_post_types = array(
- 'post' => 'dashicons-admin-post',
- 'page' => 'dashicons-admin-page',
+ 'post' => 'dashicons-admin-post',
+ 'page' => 'dashicons-admin-page',
'attachment' => 'dashicons-admin-media',
);
- if ( empty($icon) && isset($standard_post_types[$post_type['name']]) ) {
+ if ( empty( $icon ) && isset( $standard_post_types[ $post_type['name'] ] ) ) {
$icon = $standard_post_types[ $post_type['name'] ];
}
- if ( empty($icon) ) {
+ if ( empty( $icon ) ) {
$icon = 'dashicons-admin-post';
}
@@ -100,6 +117,8 @@ function jcf_get_post_type_icon( $post_type ) {
* Similar to WP get_page_templates(), but searches more folder levels
* Required to support _jmvt theme boilerplate
*
+ * @param mixed $post_type Post type.
+ *
* @return array updated page templates array
*/
function jcf_get_page_templates( $post_type = 'page' ) {
@@ -114,30 +133,30 @@ function jcf_get_page_templates( $post_type = 'page' ) {
$files = $wp_theme->get_files( 'php', 2 );
if ( $wp_theme->parent() ) {
$parent_files = $wp_theme->parent()->get_files( 'php', 2 );
- $files = array_merge( $parent_files, $files );
+ $files = array_merge( $parent_files, $files );
}
- foreach ($files as $file => $full_path) {
- if ( $full_path === __FILE__
- || preg_match( '#^(core|inc|app|functions.php)/#', $file )
- || !preg_match( '|Template Name:(.*)$|mi', file_get_contents($full_path), $header )
+ foreach ( $files as $file => $full_path ) {
+ if ( __FILE__ === $full_path
+ || preg_match( '#^(core|inc|app|functions.php)/#', $file )
+ || ! preg_match( '|Template Name:(.*)$|mi', file_get_contents( $full_path ), $header )
) {
continue;
}
- $types = array('page');
- if (preg_match('|Template Post Type:(.*)$|mi', file_get_contents($full_path), $type)) {
- $types = explode(',', _cleanup_header_comment($type[1]));
+ $types = array( 'page' );
+ if ( preg_match( '|Template Post Type:(.*)$|mi', file_get_contents( $full_path ), $type ) ) {
+ $types = explode( ',', _cleanup_header_comment( $type[1] ) );
}
- foreach ($types as $type) {
- $type = sanitize_key($type);
- if ( !isset($post_templates[$type]) ) {
- $post_templates[$type] = array();
+ foreach ( $types as $type ) {
+ $type = sanitize_key( $type );
+ if ( ! isset( $post_templates[ $type ] ) ) {
+ $post_templates[ $type ] = array();
}
if ( $post_type == $type ) {
- $post_templates[$type][$file] = _cleanup_header_comment($header[1]);
+ $post_templates[ $type ][ $file ] = _cleanup_header_comment( $header[1] );
}
}
}
@@ -145,100 +164,109 @@ function jcf_get_page_templates( $post_type = 'page' ) {
wp_cache_add( 'jcf_post_templates_depth2', $deep_templates, 'themes', 1800 );
}
- if ( !empty($post_templates[$post_type]) ) {
- $page_templates = array_merge(array('default' => 'Default'), $post_templates[$post_type]);
+ if ( ! empty( $post_templates[ $post_type ] ) ) {
+ $page_templates = array_merge( array( 'default' => 'Default' ), $post_templates[ $post_type ] );
}
return $page_templates;
}
/**
- * javascript localization
+ * Javascript localization
+ *
* @return array
*/
function jcf_get_language_strings() {
global $wp_version;
$strings = array(
- 'hi' => __('Hello there', \JustCustomFields::TEXTDOMAIN),
- 'edit' => __('Edit', \JustCustomFields::TEXTDOMAIN),
- 'delete' => __('Delete', \JustCustomFields::TEXTDOMAIN),
- 'confirm_field_delete' => __('Are you sure you want to delete selected field?', \JustCustomFields::TEXTDOMAIN),
- 'confirm_fieldset_delete' => __("Are you sure you want to delete the fieldset?\nAll fields will be also deleted!", \JustCustomFields::TEXTDOMAIN),
- 'err_fieldset_visibility_invalid' => __('You should select Taxonomy term to continue.', \JustCustomFields::TEXTDOMAIN),
- 'err_fieldset_visibility_invalid_page' => __('You should select Taxonomy term or Page template to continue.', \JustCustomFields::TEXTDOMAIN),
- 'select_image' => __('Select', \JustCustomFields::TEXTDOMAIN),
- 'update_image' => __('Update Image', \JustCustomFields::TEXTDOMAIN),
- 'update_file' => __('Update File', \JustCustomFields::TEXTDOMAIN),
- 'yes' => __('Yes', \JustCustomFields::TEXTDOMAIN),
- 'no' => __('No', \JustCustomFields::TEXTDOMAIN),
- 'no_term' => __('The term doesn\'t exist', \JustCustomFields::TEXTDOMAIN),
- 'no_templates' => __('The template doesn\'t exist', \JustCustomFields::TEXTDOMAIN),
- 'slug' => __('Slug', \JustCustomFields::TEXTDOMAIN),
- 'type' => __('Type', \JustCustomFields::TEXTDOMAIN),
- 'enabled' => __('Enabled', \JustCustomFields::TEXTDOMAIN),
- 'wp_version' => $wp_version,
+ 'hi' => __( 'Hello there', 'jcf' ),
+ 'edit' => __( 'Edit', 'jcf' ),
+ 'delete' => __( 'Delete', 'jcf' ),
+ 'confirm_field_delete' => __( 'Are you sure you want to delete selected field?', 'jcf' ),
+ 'confirm_fieldset_delete' => __( "Are you sure you want to delete the fieldset?\nAll fields will be also deleted!", 'jcf' ),
+ 'err_fieldset_visibility_invalid' => __( 'You should select Taxonomy term to continue.', 'jcf' ),
+ 'err_fieldset_visibility_invalid_page' => __( 'You should select Taxonomy term or Page template to continue.', 'jcf' ),
+ 'select_image' => __( 'Select', 'jcf' ),
+ 'update_image' => __( 'Update Image', 'jcf' ),
+ 'update_file' => __( 'Update File', 'jcf' ),
+ 'yes' => __( 'Yes', 'jcf' ),
+ 'no' => __( 'No', 'jcf' ),
+ 'no_term' => __( 'The term doesn\'t exist', 'jcf' ),
+ 'no_templates' => __( 'The template doesn\'t exist', 'jcf' ),
+ 'slug' => __( 'Slug', 'jcf' ),
+ 'type' => __( 'Type', 'jcf' ),
+ 'enabled' => __( 'Enabled', 'jcf' ),
+ 'wp_version' => $wp_version,
);
- $strings = apply_filters('jcf_localize_script_strings', $strings);
+ $strings = apply_filters( 'jcf_localize_script_strings', $strings );
+
return $strings;
}
/**
- * Json formater
- * @param string $json Data of settings for fields
- * @return string Return formated json string with settings for fields
+ * Json formater
+ *
+ * @param string $json Data of settings for fields.
+ *
+ * @return string Return formated json string with settings for fields
*/
function jcf_format_json( $json ) {
- $result = '';
- $level = 0;
- $in_quotes = false;
- $in_escape = false;
- $ends_line_level = NULL;
- $json_length = strlen( $json );
-
- for( $i = 0; $i < $json_length; $i++ ) {
- $char = $json[$i];
- $new_line_level = NULL;
- $post = "";
- if( $ends_line_level !== NULL ) {
- $new_line_level = $ends_line_level;
- $ends_line_level = NULL;
+ $result = '';
+ $level = 0;
+ $in_quotes = false;
+ $in_escape = false;
+ $ends_line_level = null;
+ $json_length = strlen( $json );
+
+ for ( $i = 0; $i < $json_length; $i ++ ) {
+ $char = $json[ $i ];
+ $new_line_level = null;
+ $post = '';
+ if ( null !== $ends_line_level ) {
+ $new_line_level = $ends_line_level;
+ $ends_line_level = null;
}
if ( $in_escape ) {
$in_escape = false;
- } else if( $char === '"' ) {
- $in_quotes = !$in_quotes;
- } else if( ! $in_quotes ) {
- switch( $char ) {
- case '}': case ']':
- $level--;
- $ends_line_level = NULL;
- $new_line_level = $level;
- break;
-
- case '{': case '[':
- $level++;
+ } elseif ( '"' === $char ) {
+ $in_quotes = ! $in_quotes;
+ } elseif ( ! $in_quotes ) {
+ switch ( $char ) {
+ case '}':
+ case ']':
+ $level --;
+ $ends_line_level = null;
+ $new_line_level = $level;
+ break;
+
+ case '{':
+ case '[':
+ $level ++;
case ',':
$ends_line_level = $level;
break;
case ':':
- $post = " ";
+ $post = ' ';
break;
- case " ": case "\t": case "\n": case "\r":
- $char = "";
- $ends_line_level = $new_line_level;
- $new_line_level = NULL;
- break;
+ case ' ':
+ case "\t":
+ case "\n":
+ case "\r":
+ $char = '';
+ $ends_line_level = $new_line_level;
+ $new_line_level = null;
+ break;
}
- } else if ( $char === '\\' ) {
+ } else if ( '\\' === $char ) {
$in_escape = true;
}
- if( $new_line_level !== NULL ) {
- $result .= "\n".str_repeat( "\t", $new_line_level );
+ if ( null !== $new_line_level ) {
+ $result .= "\n" . str_repeat( "\t", $new_line_level );
}
- $result .= $char.$post;
+ $result .= $char . $post;
}
return $result;
@@ -246,22 +274,23 @@ function jcf_format_json( $json ) {
/**
* Set permisiions for file
- * @param string $dir Parent directory path
- * @param string $filename File path
+ *
+ * @param string $filename File path.
+ *
* @return boolean
*/
function jcf_set_chmod( $filename ) {
- $dir_perms = fileperms(dirname($filename));
- if ( @chmod($filename, $dir_perms) ) {
+ $dir_perms = fileperms( dirname( $filename ) );
+ if ( @chmod( $filename, $dir_perms ) ) {
return true;
- }
- else {
+ } else {
return false;
}
}
/**
- * print image with loader
+ * Print image with loader
+ *
* @deprecated
*/
function jcf_print_loader_img() {
@@ -269,68 +298,81 @@ function jcf_print_loader_img() {
}
/**
- * safety print html tag attributes
+ * Safety print html tag attributes
+ *
+ * @param array $attributes Attributes.
+ * @param bool $echo Echo.
*
- * @param array $attributes
* @return string|boolean
*/
function jcf_html_attributes( array $attributes = array(), $echo = true ) {
- if( empty($attributes) ) return '';
+ if ( empty( $attributes ) ) {
+ return '';
+ }
$html = array();
foreach ( $attributes as $attr => $value ) {
- $html[] = $attr . '="' . esc_attr($value) . '"';
+ $html[] = $attr . '="' . esc_attr( $value ) . '"';
}
- $html = ' ' . implode(' ', $html);
+ $html = ' ' . implode( ' ', $html );
- if ( $echo )
+ if ( $echo ) {
echo $html;
- else
+ } else {
return $html;
+ }
}
/**
* Generate starting HTML tag
*
- * @param string $tag
- * @param array $attributes
+ * @param string $tag Tag.
+ * @param array $attributes Attribute.
+ *
* @return string
*/
function jcf_html_tag( $tag, array $attributes = array() ) {
- $html_attributes = jcf_html_attributes($attributes, false);
- $html = "<{$tag}{$html_attributes}>";
+ $html_attributes = jcf_html_attributes( $attributes, false );
+ $html = "<{$tag}{$html_attributes}>";
+
return $html;
}
/**
* Generate input type hidden
*
- * @param array $attributes
+ * @param array $attributes Attributes.
+ *
* @return string
*/
function jcf_html_hidden_input( array $attributes = array() ) {
$attributes['type'] = 'hidden';
- return jcf_html_tag('input', $attributes);
+
+ return jcf_html_tag( 'input', $attributes );
}
/**
* Generate input type checkbox
*
- * @param array $attributes
+ * @param array $attributes Attrubutes.
+ *
* @return string
*/
function jcf_html_checkbox( array $attributes = array() ) {
$attributes['type'] = 'checkbox';
- return jcf_html_tag('input', $attributes);
+
+ return jcf_html_tag( 'input', $attributes );
}
/**
* Special function which wraps HTML special characters inside the textarea
*
- * @param string $value
+ * @param string $value Value.
+ *
* @return string
*/
function jcf_esc_textarea( $value ) {
$safe_text = htmlspecialchars( $value, ENT_NOQUOTES, get_option( 'blog_charset' ) );
+
return $safe_text;
}
diff --git a/just-custom-fields.php b/just-custom-fields.php
index 971a783..f43b793 100755
--- a/just-custom-fields.php
+++ b/just-custom-fields.php
@@ -6,37 +6,38 @@
Tags: custom, fields, custom fields, meta, post meta, object meta, editor, custom gallery, collection, field group, metabox, fieldsets
Author: JustCoded / Alex Prokopenko
Author URI: http://justcoded.com/
-Version: 3.3
+Version: 3.2
*/
-define('JCF_ROOT', dirname(__FILE__));
-require_once( JCF_ROOT.'/core/Autoload.php' );
-require_once( JCF_ROOT.'/functions/helpers.php' );
+define( 'JCF_ROOT', dirname( __FILE__ ) );
+require_once( JCF_ROOT . '/core/Autoload.php' );
+require_once( JCF_ROOT . '/functions/helpers.php' );
use jcf\core;
use jcf\controllers;
-class JustCustomFields extends core\Singleton
-{
+/**
+ * Class JustCustomFields
+ */
+class JustCustomFields extends core\Singleton {
/**
* Plugin text domain for translations
*/
- const TEXTDOMAIN = 'just-custom-fields';
- const VERSION = '3.300';
+ const VERSION = '3.200';
/**
* Textual plugin name
*
* @var string
*/
- public static $pluginName;
+ public static $plugin_name;
/**
* Variable-style plugin name
*
* @var string
*/
- public static $pluginSlug = 'just_custom_fields';
+ public static $plugin_slug = 'just_custom_fields';
/**
* Current plugin version
@@ -55,43 +56,35 @@ class JustCustomFields extends core\Singleton
/**
* Plugin main entry point
*
- * protected constructor prevents creating another plugin instance with "new" operator
+ * Protected constructor prevents creating another plugin instance with "new" operator
*/
- protected function __construct()
- {
- // init plugin name and version
- self::$pluginName = __('Just Custom Fields', JustCustomFields::TEXTDOMAIN);
- self::$version = self::VERSION;
-
- // run all init actions after theme setup to be able to add hooks from theme
- add_action('after_setup_theme', array($this, 'safeInit'));
- }
+ protected function __construct() {
+ /* init plugin name and version */
+ self::$plugin_name = __( 'Just Custom Fields', 'jcf' );
+ self::$version = self::VERSION;
- public function safeInit()
- {
- // init features, which this plugin is created for
- $this->initControllers();
+ /* init features, which this plugin is created for */
+ $this->init_controllers();
- // init all standard available field components
- $this->initFields();
+ $this->init_fields();
+ add_action( 'plugins_loaded', array( $this, 'register_custom_components' ) );
}
/**
* Init all controllers to support post edit pages and admin configuration pages
*/
- public function initControllers()
- {
+ public function init_controllers() {
$loader = new core\PluginLoader();
- // we use wp_doing_ajax to prevent version check under ajax
- if ( ! wp_doing_ajax() && $loader->checkMigrationsAvailable() ) {
+ /* we use wp_doing_ajax to prevent version check under ajax */
+ if ( ! wp_doing_ajax() && $loader->check_migrations_available() ) {
new controllers\MigrateController();
new controllers\AdminController();
- }
- else {
+ } else {
new controllers\PostTypeController();
- new controllers\TaxonomyController();
- if ( !is_admin() ) return;
+ if ( ! is_admin() ) {
+ return;
+ }
new controllers\AdminController();
new controllers\SettingsController();
@@ -104,83 +97,89 @@ public function initControllers()
/**
* Init field components (field types, which can be added to post type)
*/
- public function initFields()
- {
- $this->registerField( 'jcf\components\inputtext\JustField_InputText', true );
- $this->registerField( 'jcf\components\textarea\JustField_Textarea', true );
- $this->registerField( 'jcf\components\select\JustField_Select', true );
- $this->registerField( 'jcf\components\selectmultiple\JustField_SelectMultiple', true );
- $this->registerField( 'jcf\components\checkbox\JustField_Checkbox', true );
- $this->registerField( 'jcf\components\datepicker\JustField_DatePicker', true );
- $this->registerField( 'jcf\components\simplemedia\JustField_SimpleMedia', true );
- $this->registerField( 'jcf\components\collection\JustField_Collection' );
- $this->registerField( 'jcf\components\table\JustField_Table', true );
- $this->registerField( 'jcf\components\relatedcontent\JustField_RelatedContent', true );
- $this->registerField( 'jcf\components\googlemaps\JustField_GoogleMaps', true );
-
- /**
- * Registration of custom components from themes and other plugins
- *
- * to add more your owrn component within a theme or a plugin:
- * - register callback function for action 'jcf_register_fields'
- * - include your components files
- * - run
- * $jcf = new \JustCustomFields();
- * $jcf->registerField('namespace\className', $collection_field = true|false);
- *
- */
+ public function init_fields() {
+ $this->register_field( 'jcf\components\inputtext\JustField_InputText', true );
+ $this->register_field( 'jcf\components\textarea\JustField_Textarea', true );
+ $this->register_field( 'jcf\components\select\JustField_Select', true );
+ $this->register_field( 'jcf\components\selectmultiple\JustField_SelectMultiple', true );
+ $this->register_field( 'jcf\components\checkbox\JustField_Checkbox', true );
+ $this->register_field( 'jcf\components\datepicker\JustField_DatePicker', true );
+ $this->register_field( 'jcf\components\simplemedia\JustField_SimpleMedia', true );
+ $this->register_field( 'jcf\components\collection\JustField_Collection' );
+ $this->register_field( 'jcf\components\table\JustField_Table', true );
+ $this->register_field( 'jcf\components\relatedcontent\JustField_RelatedContent', true );
+ $this->register_field( 'jcf\components\googlemaps\JustField_GoogleMaps', true );
+ }
+
+ /**
+ * Launch hook to be able to register mode components from themes and other plugins
+ *
+ * To add more field components with your custom code:
+ * - add_action 'jcf_register_fields'
+ * - include your components files
+ * - run
+ * $jcf = new \JustCustomFields();
+ * $jcf->register_field('namespace\className', $collection_field = true|false);
+ */
+ public function register_custom_components() {
do_action( 'jcf_register_fields' );
}
/**
- * register field component
+ * Register field component
*
- * @param $class_name
- * @param bool $collection_field
- * @return bool
+ * @param mixed $class_name Class name.
+ * @param bool $collection_field Collection field.
*/
- public function registerField( $class_name, $collection_field = false )
- {
- if ( strpos($class_name, '\\') === FALSE ) $class_name = '\\' . $class_name;
+ public function register_field( $class_name, $collection_field = false ) {
+ if ( strpos( $class_name, '\\' ) === false ) {
+ $class_name = '\\' . $class_name;
+ }
$field_obj = new $class_name();
$field = array(
- 'id_base' => $field_obj->idBase,
+ 'id_base' => $field_obj->id_base,
'class' => $class_name,
'title' => $field_obj->title,
'collection_field' => $collection_field,
);
- $this->_fields[$field_obj->idBase] = $field;
+ $this->_fields[ $field_obj->id_base ] = $field;
}
-
+
/**
- * return array of registered fields
+ * Return array of registered fields
+ *
+ * @param bool $collection_only Collection only.
+ *
+ * @return array $collection_fields
*/
- public function getFields( $collection_only = false )
- {
- if ( ! $collection_only )
+ public function get_fields( $collection_only = false ) {
+ if ( ! $collection_only ) {
return $this->_fields;
-
- // filter by collection availability
+ }
+ /* filter by collection availability */
$collection_fields = array();
- foreach ($this->_fields as $f) {
- if ( !$f['collection_field'] ) continue;
- $collection_fields[ $f['id_base'] ] = $f;
+ foreach ( $this->_fields as $f ) {
+ if ( ! $f['collection_field'] ) {
+ continue;
+ }
+ $collection_fields[] = $f;
}
-
+
return $collection_fields;
}
-
+
/**
* Field info (title, id_base, class)
- * @param string $id_base
+ *
+ * @param string $id_base ID base.
+ *
* @return array
*/
- public function getFieldInfo($id_base)
- {
- if ( !empty($this->_fields[$id_base]) ) {
- return $this->_fields[$id_base];
+ public function get_field_info( $id_base ) {
+ if ( ! empty( $this->_fields[ $id_base ] ) ) {
+ return $this->_fields[ $id_base ];
}
return null;
}
@@ -188,4 +187,3 @@ public function getFieldInfo($id_base)
}
JustCustomFields::run();
-
diff --git a/migrations/m3x000.php b/migrations/m3x000.php
index 2fff461..108e03d 100644
--- a/migrations/m3x000.php
+++ b/migrations/m3x000.php
@@ -17,50 +17,63 @@
*
* @package jcf\migrations
*/
-class m3x000 extends \jcf\core\Migration
-{
+class m3x000 extends \jcf\core\Migration {
+
+ /**
+ * Version number
+ *
+ * @var $version
+ */
protected $version = '3.000';
+
+ /**
+ * Version number
+ *
+ * @var $unique
+ */
protected $unique = 0;
/**
* Read data from storage
*/
- protected function readData()
- {
- $fields = array();
+ protected function read_data() {
+ $fields = array();
$fieldsets = array();
- // read from DB
- if ( $this->isDataSource( Settings::CONF_SOURCE_DB ) ) {
+ // read from DB.
+ if ( $this->is_data_source( Settings::CONF_SOURCE_DB ) ) {
$post_types = jcf_get_post_types();
foreach ( $post_types as $post_type => $object ) {
- $p_fieldsets = $this->readDB("jcf_fieldsets-{$post_type}");
- if ( empty($p_fieldsets) ) continue;
+ $p_fieldsets = $this->read_db( "jcf_fieldsets-{$post_type}" );
+ if ( empty( $p_fieldsets ) ) {
+ continue;
+ }
- $p_fields = $this->readDB("jcf_fields-{$post_type}");
- if ( empty($p_fields) ) $p_fields = array();
+ $p_fields = $this->read_db( "jcf_fields-{$post_type}" );
+ if ( empty( $p_fields ) ) {
+ $p_fields = array();
+ }
- $fields[$post_type] = $p_fields;
- $fieldsets[$post_type] = $p_fieldsets;
+ $fields[ $post_type ] = $p_fields;
+ $fieldsets[ $post_type ] = $p_fieldsets;
}
- }
- // read from FS
+ } // read from FS
else {
- $json = $this->readFS('jcf-settings/jcf_settings.json');
- $data = json_decode($json, true);
-
- if ( !empty($data['fieldsets']) ) {
- foreach ($data['fieldsets'] as $post_type => $fieldsets_array) {
- if ( !empty($fieldsets_array) ) {
- $fieldsets[$post_type] = $fieldsets_array;
- $fields[$post_type] = array();
+ $json = $this->read_fs( 'jcf-settings/jcf_settings.json' );
+ $data = json_decode( $json, true );
+
+ if ( ! empty( $data['fieldsets'] ) ) {
+ foreach ( $data['fieldsets'] as $post_type => $fieldsets_array ) {
+ if ( ! empty( $fieldsets_array ) ) {
+ $fieldsets[ $post_type ] = $fieldsets_array;
+ $fields[ $post_type ] = array();
}
}
- if ( !empty($data['field_settings']) ) {
- foreach ($data['field_settings'] as $post_type => $fields_array) {
- if ( !empty($fields_array) ) {
- $fields[$post_type] = $fields_array;
+ if ( ! empty( $data['field_settings'] ) ) {
+ foreach ( $data['field_settings'] as $post_type => $fields_array ) {
+ if ( ! empty( $fields_array ) ) {
+ $fields[ $post_type ] = $fields_array;
}
}
}
@@ -68,7 +81,7 @@ protected function readData()
}
$this->data = array(
- self::FIELDS_KEY => $fields,
+ self::FIELDS_KEY => $fields,
self::FIELDSETS_KEY => $fieldsets,
);
}
@@ -78,32 +91,30 @@ protected function readData()
*
* @return bool
*/
- protected function test()
- {
- if ( ! $deprecated = $this->findDeprecatedFields() ) {
+ protected function test() {
+ if ( ! $deprecated = $this->find_deprecated_fields() ) {
return false;
}
- $warnings = array();
- $post_types = get_post_types(array(), 'objects');
+ $warnings = array();
+ $post_types = get_post_types( array(), 'objects' );
$not_registered_post_types = false;
- foreach ($deprecated as $post_type => $fields) {
- $pt_title = ucfirst($post_type) . '*';
- if ( isset($post_types[$post_type]) ) {
- $pt = $post_types[$post_type];
+ foreach ( $deprecated as $post_type => $fields ) {
+ $pt_title = ucfirst( $post_type ) . '*';
+ if ( isset( $post_types[ $post_type ] ) ) {
+ $pt = $post_types[ $post_type ];
$pt_title = $pt->label;
- }
- else {
+ } else {
$not_registered_post_types = true;
}
$field_names = array();
- foreach ($fields as $field) {
+ foreach ( $fields as $field ) {
$field_names[] = "{$field['full_title']} ({$field['field_type']})";
}
- $warnings[] = "$pt_title fields " . implode(', ', $field_names) . " will be converted.";
+ $warnings[] = '$pt_title fields ' . implode( ', ', $field_names ) . ' will be converted.';
}
$html = '
@@ -114,11 +125,11 @@ protected function test()
You will need to upgrade your templates to read data from new fields/format.
- ' . implode(' ', $warnings) . '
+ ' . implode( ' ', $warnings ) . '
';
- if ($not_registered_post_types) {
+ if ( $not_registered_post_types ) {
$html .= '* Post type is not registered anymore.
';
}
@@ -131,29 +142,30 @@ protected function test()
*
* @return array
*/
- protected function findDeprecatedFields()
- {
- $deprecated = array();
- $all_fields = $this->data[self::FIELDS_KEY];
- $all_fieldsets = $this->data[self::FIELDSETS_KEY];
-
- foreach ($all_fieldsets as $post_type => $fieldsets) {
- foreach ($fieldsets as $fieldset_id => $fieldset) {
- if ( empty($fieldset['fields']) ) continue;
-
- foreach ($fieldset['fields'] as $field_id => $dummy_value) {
- // check usual fields
- if ( preg_match('/^(uploadmedia|fieldsgroup)\-/', $field_id, $match) && isset($all_fields[$post_type][$field_id]) ) {
+ protected function find_deprecated_fields() {
+ $deprecated = array();
+ $all_fields = $this->data[ self::FIELDS_KEY ];
+ $all_fieldsets = $this->data[ self::FIELDSETS_KEY ];
+
+ foreach ( $all_fieldsets as $post_type => $fieldsets ) {
+ foreach ( $fieldsets as $fieldset_id => $fieldset ) {
+ if ( empty( $fieldset['fields'] ) ) {
+ continue;
+ }
+
+ foreach ( $fieldset['fields'] as $field_id => $dummy_value ) {
+ // check usual fields.
+ if ( preg_match( '/^(uploadmedia|fieldsgroup)\-/', $field_id, $match ) && isset( $all_fields[ $post_type ][ $field_id ] ) ) {
if ( ! isset( $deprecated[ $post_type ] ) ) {
$deprecated[ $post_type ] = array();
}
- $field = $all_fields[$post_type][$field_id];
+ $field = $all_fields[ $post_type ][ $field_id ];
- $deprecated[$post_type][$field_id] = array(
- 'title' => $field['title'],
- 'full_title' => $field['title'],
- 'field_type' => $match[1],
+ $deprecated[ $post_type ][ $field_id ] = array(
+ 'title' => $field['title'],
+ 'full_title' => $field['title'],
+ 'field_type' => $match[1],
'fieldset_id' => $fieldset_id,
);
}
@@ -169,96 +181,97 @@ protected function findDeprecatedFields()
*
* @return boolean
*/
- protected function update()
- {
- set_time_limit(0);
- $all_fields = $this->data[self::FIELDS_KEY];
- $all_fieldsets = $this->data[self::FIELDSETS_KEY];
- $this->unique = time();
+ protected function update() {
+ set_time_limit( 0 );
+ $all_fields = $this->data[ self::FIELDS_KEY ];
+ $all_fieldsets = $this->data[ self::FIELDSETS_KEY ];
+ $this->unique = time();
$existed_fields = array();
- foreach ($all_fieldsets as $post_type => $fieldsets) {
- $existed_fields[$post_type] = array();
+ foreach ( $all_fieldsets as $post_type => $fieldsets ) {
+ $existed_fields[ $post_type ] = array();
- foreach ($fieldsets as $fieldset_id => $fieldset) {
+ foreach ( $fieldsets as $fieldset_id => $fieldset ) {
$fieldset['position'] = 'advanced';
$fieldset['priority'] = 'default';
- if ( empty($fieldset['fields']) ) {
- $fieldset['fields'] = array();
- $all_fieldsets[$post_type][$fieldset_id] = $fieldset;
+ if ( empty( $fieldset['fields'] ) ) {
+ $fieldset['fields'] = array();
+ $all_fieldsets[ $post_type ][ $fieldset_id ] = $fieldset;
continue;
}
- foreach ($fieldset['fields'] as $field_id => $dummy_value) {
- if ( ! isset($all_fields[$post_type][$field_id]) ) continue;
+ foreach ( $fieldset['fields'] as $field_id => $dummy_value ) {
+ if ( ! isset( $all_fields[ $post_type ][ $field_id ] ) ) {
+ continue;
+ }
- $existed_fields[$post_type][] = $field_id;
+ $existed_fields[ $post_type ][] = $field_id;
- // convert select options
- if ( preg_match('/^(select|selectmultiple)\-/', $field_id, $match) ) {
- $field = $all_fields[$post_type][$field_id];
- $all_fields[$post_type][$field_id] = $this->updateSelectField($field, $post_type);
+ // convert select options.
+ if ( preg_match( '/^(select|selectmultiple)\-/', $field_id, $match ) ) {
+ $field = $all_fields[ $post_type ][ $field_id ];
+ $all_fields[ $post_type ][ $field_id ] = $this->update_select_field( $field, $post_type );
}
- // check fieldsgroup and upload media
- if ( preg_match('/^(fieldsgroup|uploadmedia)\-/', $field_id, $match) ) {
- $field = $all_fields[$post_type][$field_id];
+ // check fieldsgroup and upload media.
+ if ( preg_match( '/^(fieldsgroup|uploadmedia)\-/', $field_id, $match ) ) {
+ $field = $all_fields[ $post_type ][ $field_id ];
- $collection_id = 'collection-' . $this->unique++;
+ $collection_id = 'collection-' . $this->unique ++;
- // generate new collection
- if ( 'fieldsgroup' === $match[1] ){
- $collection = $this->updateFieldsgroup($field, $post_type);
+ // generate new collection.
+ if ( 'fieldsgroup' === $match[1] ) {
+ $collection = $this->update_fieldsgroup( $field, $post_type );
}
- if ( 'uploadmedia' === $match[1] ){
- $collection = $this->updateUploadmedia($field, $post_type);
+ if ( 'uploadmedia' === $match[1] ) {
+ $collection = $this->update_uploadmedia( $field, $post_type );
}
- unset($all_fields[$post_type][$field_id]);
- unset($fieldset['fields'][$field_id]);
+ unset( $all_fields[ $post_type ][ $field_id ] );
+ unset( $fieldset['fields'][ $field_id ] );
- $fieldset['fields'][$collection_id] = $collection_id;
- $all_fields[$post_type][$collection_id] = $collection;
- $all_fields[$post_type] = array_merge($all_fields[$post_type], $collection['fields']);
+ $fieldset['fields'][ $collection_id ] = $collection_id;
+ $all_fields[ $post_type ][ $collection_id ] = $collection;
+ $all_fields[ $post_type ] = array_merge( $all_fields[ $post_type ], $collection['fields'] );
- $existed_fields[$post_type][] = $collection_id;
- $existed_fields[$post_type] = array_merge($existed_fields[$post_type], array_keys($collection['fields']));
+ $existed_fields[ $post_type ][] = $collection_id;
+ $existed_fields[ $post_type ] = array_merge( $existed_fields[ $post_type ], array_keys( $collection['fields'] ) );
}
- // check collection to record existed fields from collections as well
- if ( preg_match('/^(collection)\-/', $field_id, $match) ) {
- $collection = $all_fields[$post_type][$field_id];
- if ( !empty($collection['fields']) ) {
- $existed_fields[$post_type] = array_merge($existed_fields[$post_type], array_keys($collection['fields']));
+ // check collection to record existed fields from collections as well.
+ if ( preg_match( '/^(collection)\-/', $field_id, $match ) ) {
+ $collection = $all_fields[ $post_type ][ $field_id ];
+ if ( ! empty( $collection['fields'] ) ) {
+ $existed_fields[ $post_type ] = array_merge( $existed_fields[ $post_type ], array_keys( $collection['fields'] ) );
}
}
}
- // update fieldset itself
- $all_fieldsets[$post_type][$fieldset_id] = $fieldset;
+ // update fieldset itself.
+ $all_fieldsets[ $post_type ][ $fieldset_id ] = $fieldset;
}
}
- // clean up fields and add new keys
- foreach ($all_fields as $post_type => $fields) {
- foreach ($fields as $field_id => $field) {
- // delete missing fields
- if (!isset($existed_fields[$post_type]) || !in_array($field_id, $existed_fields[$post_type]) || empty($field)) {
- unset($all_fields[$post_type][$field_id]);
+ // clean up fields and add new keys.
+ foreach ( $all_fields as $post_type => $fields ) {
+ foreach ( $fields as $field_id => $field ) {
+ // delete missing fields.
+ if ( ! isset( $existed_fields[ $post_type ] ) || ! in_array( $field_id, $existed_fields[ $post_type ] ) || empty( $field ) ) {
+ unset( $all_fields[ $post_type ][ $field_id ] );
continue;
}
- // add field type key to all fields
- if ( preg_match('/^([a-z0-9]+)\-/i', $field_id, $match) ) {
- $all_fields[$post_type][$field_id]['_type'] = $match[1];
+ // add field type key to all fields.
+ if ( preg_match( '/^([a-z0-9]+)\-/i', $field_id, $match ) ) {
+ $all_fields[ $post_type ][ $field_id ]['_type'] = $match[1];
}
}
}
$this->data = array(
- self::FIELDS_KEY => $all_fields,
+ self::FIELDS_KEY => $all_fields,
self::FIELDSETS_KEY => $all_fieldsets,
);
@@ -268,17 +281,18 @@ protected function update()
/**
* Some old versions has key 'settings', but new component works with key 'options'
*
- * @param array $field
- * @param string $post_type
+ * @param array $field Field.
+ * @param string $post_type Post type.
+ *
* @return array
*/
- protected function updateSelectField( $field, $post_type )
- {
- if ( empty($field['options']) && !empty($field['settings']) ) {
+ protected function update_select_field( $field, $post_type ) {
+ if ( empty( $field['options'] ) && ! empty( $field['settings'] ) ) {
$field['options'] = $field['settings'];
- unset($field['settings']);
+ unset( $field['settings'] );
}
$field['_version'] = $this->version;
+
return $field;
}
@@ -286,46 +300,45 @@ protected function updateSelectField( $field, $post_type )
* Create new collection field settings instead of fieldsgroup
* Migrate data to new slug in DB
*
- * @param array $field
- * @param string $post_type
+ * @param array $field Field.
+ * @param string $post_type Post type.
*
* @return array
*/
- protected function updateFieldsgroup($field, $post_type)
- {
- // prepare new collection settings config
- $new_slug = '_' . ltrim($field['slug'], '_') . '_v3';
+ protected function update_fieldsgroup( $field, $post_type ) {
+ // prepare new collection settings config.
+ $new_slug = '_' . ltrim( $field['slug'], '_' ) . '_v3';
$new_collection = array(
- 'title' => $field['title'],
- 'slug' => $new_slug,
- 'enabled' => $field['enabled'],
+ 'title' => $field['title'],
+ 'slug' => $new_slug,
+ 'enabled' => $field['enabled'],
'_version' => $this->version,
- '_type' => 'collection',
- 'fields' => array(),
+ '_type' => 'collection',
+ 'fields' => array(),
);
- $field['fields'] = trim($field['fields']);
- $fieldsgroup_fields = explode("\n", $field['fields']);
+ $field['fields'] = trim( $field['fields'] );
+ $fieldsgroup_fields = explode( "\n", $field['fields'] );
- // insert inputtext into collection
- if ( !empty($fieldsgroup_fields) ) {
+ // insert inputtext into collection.
+ if ( ! empty( $fieldsgroup_fields ) ) {
$is_group_title = 1;
foreach ( $fieldsgroup_fields as $line ) {
- // parse settings
- $line = trim($line);
- $params = explode('|', $line, 2);
- if ( empty($params[1]) ) {
+ // parse settings.
+ $line = trim( $line );
+ $params = explode( '|', $line, 2 );
+ if ( empty( $params[1] ) ) {
$params[1] = $params[0];
}
- $new_collection['fields'][ 'inputtext-' . $this->unique++ ] = array(
- 'title' => $params[1],
+ $new_collection['fields'][ 'inputtext-' . $this->unique ++ ] = array(
+ 'title' => $params[1],
'description' => '',
- 'slug' => $params[0],
- 'enabled' => 1,
- '_type' => 'inputtext',
- '_version' => $this->version,
+ 'slug' => $params[0],
+ 'enabled' => 1,
+ '_type' => 'inputtext',
+ '_version' => $this->version,
'field_width' => '100',
'group_title' => $is_group_title,
);
@@ -334,9 +347,9 @@ protected function updateFieldsgroup($field, $post_type)
}
}
- // migrate DB data to new slug
- if ( ! $this->isTestMode() ) {
- $this->importPostmeta($post_type, $field['slug'], $new_slug, array($this, 'formatFieldsgroupMeta'));
+ // migrate DB data to new slug.
+ if ( ! $this->is_test_mode() ) {
+ $this->import_postmeta( $post_type, $field['slug'], $new_slug, array( $this, 'format_fieldsgroup_meta' ) );
}
return $new_collection;
@@ -346,70 +359,67 @@ protected function updateFieldsgroup($field, $post_type)
* Create new collection field settings instead of fieldsgroup
* Migrate data to new slug in DB
*
- * @param array $field
- * @param string $post_type
+ * @param array $field Field.
+ * @param string $post_type Post type.
*
* @return array
*/
- protected function updateUploadmedia($field, $post_type)
- {
- // prepare new collection settings config
- $new_slug = '_' . ltrim($field['slug'], '_') . '_v3';
+ protected function update_uploadmedia( $field, $post_type ) {
+ // prepare new collection settings config.
+ $new_slug = '_' . ltrim( $field['slug'], '_' ) . '_v3';
$new_collection = array(
- 'title' => $field['title'],
- 'slug' => $new_slug,
- 'enabled' => $field['enabled'],
+ 'title' => $field['title'],
+ 'slug' => $new_slug,
+ 'enabled' => $field['enabled'],
'_version' => $this->version,
- '_type' => 'collection',
- 'fields' => array(),
+ '_type' => 'collection',
+ 'fields' => array(),
);
- // add simple media into collection
- $new_collection['fields'][ 'simplemedia-' . $this->unique++ ] = array(
- 'title' => ($field['type'] == 'image')? 'Image' : 'File',
- 'type' => $field['type'],
+ // add simple media into collection.
+ $new_collection['fields'][ 'simplemedia-' . $this->unique ++ ] = array(
+ 'title' => ( 'image' === $field['type'] ) ? 'Image' : 'File',
+ 'type' => $field['type'],
'description' => '',
- 'slug' => 'attachment_id',
- 'enabled' => 1,
- '_type' => 'simplemedia',
- '_version' => $this->version,
+ 'slug' => 'attachment_id',
+ 'enabled' => 1,
+ '_type' => 'simplemedia',
+ '_version' => $this->version,
'field_width' => '25',
- //'group_title' => 0,
);
- // title field
- if ( !empty($field['alt_title']) ) {
- $new_collection['fields'][ 'inputtext-' . $this->unique++ ] = array(
- 'title' => 'Title',
+ // title field.
+ if ( ! empty( $field['alt_title'] ) ) {
+ $new_collection['fields'][ 'inputtext-' . $this->unique ++ ] = array(
+ 'title' => 'Title',
'description' => '',
- 'slug' => 'title',
- 'enabled' => 1,
- '_type' => 'inputtext',
- '_version' => $this->version,
+ 'slug' => 'title',
+ 'enabled' => 1,
+ '_type' => 'inputtext',
+ '_version' => $this->version,
'field_width' => '75',
'group_title' => 1,
);
}
- // description field
- if ( !empty($field['alt_descr']) ) {
- $new_collection['fields'][ 'textarea-' . $this->unique++ ] = array(
- 'title' => 'Description',
- 'editor' => 0,
+ // description field.
+ if ( ! empty( $field['alt_descr'] ) ) {
+ $new_collection['fields'][ 'textarea-' . $this->unique ++ ] = array(
+ 'title' => 'Description',
+ 'editor' => 0,
'description' => '',
- 'slug' => 'description',
- 'enabled' => 1,
- '_type' => 'textarea',
- '_version' => $this->version,
+ 'slug' => 'description',
+ 'enabled' => 1,
+ '_type' => 'textarea',
+ '_version' => $this->version,
'field_width' => '100',
- //'group_title' => 0,
);
}
- // migrate DB data to new slug
- if ( ! $this->isTestMode() ) {
- $this->importPostmeta($post_type, $field['slug'], $new_slug, array($this, 'formatUploadmediaMeta'));
+ // migrate DB data to new slug.
+ if ( ! $this->is_test_mode() ) {
+ $this->import_postmeta( $post_type, $field['slug'], $new_slug, array( $this, 'format_Uploadmedia_Meta' ) );
}
return $new_collection;
@@ -419,51 +429,51 @@ protected function updateUploadmedia($field, $post_type)
* Format fieldsgroup postmeta before save.
* Actually no changes required but we need to unserialize before writing to DB
*
- * @param \stdClass $postmeta
+ * @param \stdClass $postmeta Post meta.
*
* @return mixed
*/
- protected function formatFieldsgroupMeta($postmeta)
- {
- return maybe_unserialize($postmeta->meta_value);
+ protected function format_fieldsgroup_meta( $postmeta ) {
+ return maybe_unserialize( $postmeta->meta_value );
}
/**
* Format fieldsgroup postmeta before save.
* Actually no changes required but we need to unserialize before writing to DB
*
- * @param \stdClass $postmeta
+ * @param \stdClass $postmeta Post meta.
*
* @return mixed
*/
- protected function formatUploadmediaMeta($postmeta)
- {
- $values = maybe_unserialize($postmeta->meta_value);
- if (empty($values)) return array();
+ protected function format_Uploadmedia_Meta( $postmeta ) {
+ $values = maybe_unserialize( $postmeta->meta_value );
+ if ( empty( $values ) ) {
+ return array();
+ }
global $wpdb;
$new_values = array();
- foreach ($values as $img_data) {
+ foreach ( $values as $img_data ) {
$filename = $img_data['image'];
- $title = @$img_data['title'];
- $descr = @$img_data['description'];
+ $title = @$img_data['title'];
+ $descr = @$img_data['description'];
- // search image in media to get an ID
+ // search image in media to get an ID.
$attachment_id = $wpdb->get_var(
- $wpdb->prepare("
+ $wpdb->prepare( "
SELECT ID
FROM $wpdb->posts
WHERE post_type = 'attachment'
AND post_status = 'inherit'
AND guid = %s
- ", $filename)
+ ", $filename )
);
$new_values[] = array(
'attachment_id' => $attachment_id,
- 'title' => $title,
- 'description' => $descr,
+ 'title' => $title,
+ 'description' => $descr,
);
}
diff --git a/migrations/m3x100.php b/migrations/m3x100.php
index 45eaddb..23454a8 100644
--- a/migrations/m3x100.php
+++ b/migrations/m3x100.php
@@ -15,24 +15,21 @@
*
* @package jcf\migrations
*/
-class m3x100 extends \jcf\core\Migration
-{
+class m3x100 extends \jcf\core\Migration {
/**
* Read data from storage
*/
- public function readData()
- {
- if ( $this->isDataSource( Settings::CONF_SOURCE_DB ) ) {
- $fields = $this->readDB('jcf-fields');
- $fieldsets = $this->readDB('jcf-fieldsets');
+ public function read_data() {
+ if ( $this->is_data_source( Settings::CONF_SOURCE_DB ) ) {
+ $fields = $this->read_db( 'jcf-fields' );
+ $fieldsets = $this->read_db( 'jcf-fieldsets' );
$this->data = array(
- self::FIELDS_KEY => $fields,
+ self::FIELDS_KEY => $fields,
self::FIELDSETS_KEY => $fieldsets,
);
- }
- else {
- $json = $this->readFS('jcf-settings/jcf_settings.json');
- $this->data = json_decode($json, true);
+ } else {
+ $json = $this->read_fs( 'jcf-settings/jcf_settings.json' );
+ $this->data = json_decode( $json, true );
}
}
@@ -41,9 +38,8 @@ public function readData()
*
* @return bool
*/
- public function test()
- {
- // no compatibility issues
+ public function test() {
+ // no compatibility issues.
return false;
}
@@ -52,23 +48,20 @@ public function test()
*
* @return boolean
*/
- public function update()
- {
- // this migration doesn't have any changes in structure
+ public function update() {
+ // this migration doesn't have any changes in structure.
return true;
}
/**
* Run clean up after update
*/
- public function cleanup()
- {
- if ( $this->isDataSource( Settings::CONF_SOURCE_DB ) ) {
- $this->cleanDB('jcf-fields');
- $this->cleanDB('jcf-fieldsets');
- }
- else {
- $root = $this->getFilesRoot();
+ public function cleanup() {
+ if ( $this->is_data_source( Settings::CONF_SOURCE_DB ) ) {
+ $this->clean_db( 'jcf-fields' );
+ $this->clean_db( 'jcf-fieldsets' );
+ } else {
+ $root = $this->get_files_root();
@unlink( $root . '/jcf-settings/jcf_settings.json' );
@rmdir( $root . '/jcf-settings' );
}
diff --git a/models/DBDataLayer.php b/models/DBDataLayer.php
index 6197bb9..e973b63 100755
--- a/models/DBDataLayer.php
+++ b/models/DBDataLayer.php
@@ -10,8 +10,7 @@
*
* Define DataLayer for Database storage. Can save in single or Multisite modes
*/
-class DBDataLayer extends core\DataLayer
-{
+class DBDataLayer extends core\DataLayer {
const FIELDS_OPTION = 'jcf_fields';
const FIELDSETS_OPTION = 'jcf_fieldsets';
const STORAGEVER_OPTION = 'jcf_storage_version';
@@ -21,117 +20,123 @@ class DBDataLayer extends core\DataLayer
*
* @var string
*/
- protected $_networkMode;
+ protected $_network_mode;
/**
* DBDataLayer constructor.
*
* Init network mode settings to be used in get/update methods
*/
- public function __construct()
- {
- $this->_networkMode = models\Settings::getNetworkMode();
+ public function __construct() {
+ $this->_network_mode = models\Settings::get_network_mode();
parent::__construct();
}
/**
* Setter/Init for $this->_fields property
- * @param array $fields
+ *
+ * @param array $fields Field.
+ *
+ * @return bool
*/
- public function setFields( $fields = null )
- {
- if ( !is_null($fields) ) {
+ public function set_fields( $fields = null ) {
+ if ( ! is_null( $fields ) ) {
$this->_fields = $fields;
+
return;
}
- $this->_fields = $this->_getOptions( self::FIELDS_OPTION );
+ $this->_fields = $this->_get_options( self::FIELDS_OPTION );
}
/**
* Update fields in wp-options or wp-site-options table
*/
- public function saveFieldsData()
- {
- return $this->_updateOptions(self::FIELDS_OPTION, $this->_fields);
+ public function save_fields_data() {
+ return $this->_update_options( self::FIELDS_OPTION, $this->_fields );
}
/**
* Setter/Init for Fieldsets
- * @param array $fieldsets
+ *
+ * @param array $fieldsets Fieldset.
+ *
+ * @return bool
*/
- public function setFieldsets( $fieldsets = null )
- {
- if ( !is_null($fieldsets) ) {
+ public function set_fieldsets( $fieldsets = null ) {
+ if ( ! is_null( $fieldsets ) ) {
$this->_fieldsets = $fieldsets;
+
return;
}
- $this->_fieldsets = $this->_getOptions( self::FIELDSETS_OPTION );
+ $this->_fieldsets = $this->_get_options( self::FIELDSETS_OPTION );
}
/**
* Save fieldsets
*/
- public function saveFieldsetsData()
- {
- return $this->_updateOptions(self::FIELDSETS_OPTION, $this->_fieldsets);
+ public function save_fieldsets_data() {
+ return $this->_update_options( self::FIELDSETS_OPTION, $this->_fieldsets );
}
/**
* Get storage version
+ *
* @return array
*/
- public function getStorageVersion()
- {
- return $this->_getOptions( self::STORAGEVER_OPTION, '' );
+ public function get_storage_version() {
+ return $this->_get_options( self::STORAGEVER_OPTION, '' );
}
-
+
/**
* Update storage version
- * @param float|null $version
+ *
+ * @param float|null $version Version.
+ *
* @return boolean
*/
- public function saveStorageVersion($version = null)
- {
- if ( empty($version) ) {
+ public function save_storage_version( $version = null ) {
+ if ( empty( $version ) ) {
$version = \JustCustomFields::VERSION;
}
- return $this->_updateOptions(self::STORAGEVER_OPTION, $version);
+ return $this->_update_options( self::STORAGEVER_OPTION, $version );
}
-
+
/**
* Check NetworkMode to be set to global (multisite)
*
* @return bool
*/
- protected function isSettingsGlobal()
- {
- return $this->_networkMode == models\Settings::CONF_MS_NETWORK;
+ protected function is_settings_global() {
+ return models\Settings::CONF_MS_NETWORK === $this->_network_mode;
}
/**
* Get options with wp-options
- * @param string $key
- * @param mixed $default
+ *
+ * @param string $key Key.
+ * @param mixed $default Default.
+ *
* @return array
*/
- protected function _getOptions( $key, $default = array() )
- {
- return $this->isSettingsGlobal() ? get_site_option($key, $default) : get_option($key, $default);
+ protected function _get_options( $key, $default = array() ) {
+ return $this->is_settings_global() ? get_site_option( $key, $default ) : get_option( $key, $default );
}
/**
- * Update options with wp-options
- * @param string $key Option name
- * @param array $value Values with option name
- * @return boolean
+ * Update options with wp-options
+ *
+ * @param string $key Option name.
+ * @param array $value Values with option name.
+ *
+ * @return boolean
*/
- protected function _updateOptions( $key, $value )
- {
- $this->isSettingsGlobal() ? update_site_option($key, $value) : update_option($key, $value);
+ protected function _update_options( $key, $value ) {
+ $this->is_settings_global() ? update_site_option( $key, $value ) : update_option( $key, $value );
+
return true;
}
diff --git a/models/Field.php b/models/Field.php
index e87f033..39060bb 100644
--- a/models/Field.php
+++ b/models/Field.php
@@ -5,53 +5,101 @@
use jcf\core;
use jcf\core\JustField;
-class Field extends core\Model
-{
+/**
+ * Class Field
+ */
+class Field extends core\Model {
+
+ /**
+ * Post type
+ *
+ * @var $post_type
+ */
public $post_type;
+
+ /**
+ * Field ID
+ *
+ * @var $field_id
+ */
public $field_id;
+
+ /**
+ * Field Type
+ *
+ * @var $field_type
+ */
public $field_type;
+
+ /**
+ * Fieldset ID
+ *
+ * @var $fieldset_id
+ */
public $fieldset_id;
+
+ /**
+ * Collection ID
+ *
+ * @var $collection_id
+ */
public $collection_id;
+
+ /**
+ * Fields Order
+ *
+ * @var $fields_order
+ */
public $fields_order;
+
+ /**
+ * Group ID
+ *
+ * @var $group_id
+ */
public $group_id;
/**
* Get all fields
+ *
* @return array
*/
- public function findAll()
- {
- return $this->_dL->getFields();
+ public function find_all() {
+ return $this->_dl->get_fields();
}
/**
* Find fields by post_type
- * @param string $post_type
+ *
+ * @param string $post_type Post type.
+ *
* @return array
*/
- public function findByPostType( $post_type )
- {
- $fields = $this->_dL->getFields();
- if ( !empty($fields[$post_type]) )
- return $fields[$post_type];
+ public function find_by_post_type( $post_type ) {
+ $fields = $this->_dl->get_fields();
+ if ( ! empty( $fields[ $post_type ] ) ) {
+ return $fields[ $post_type ];
+ }
return array();
}
/**
* Find collection by post_type
- * @param string $post_type
+ *
+ * @param string $post_type Post type.
+ *
* @return array
*/
- public function findCollectionsByPostType( $post_type )
- {
- $fields = $this->_dL->getFields();
+ public function find_collections_by_post_type( $post_type ) {
+ $fields = $this->_dl->get_fields();
$collections = array();
- if ( !empty($fields[$post_type]) ) {
- foreach ( $fields[$post_type] as $field_id => $field ) {
- if ( !empty($field['fields']) )
- $collections[$field_id] = $field;
+ if ( ! empty( $fields[ $post_type ] ) ) {
+ foreach ( $fields[ $post_type ] as $field_id => $field ) {
+ if ( ! empty( $field['fields'] ) ) {
+ $collections[ $field_id ] = $field;
+ }
}
}
@@ -60,46 +108,49 @@ public function findCollectionsByPostType( $post_type )
/**
* Save new field
+ *
+ * @param mixed $import Import.
+ *
* @return boolean
*/
- public function save( $import = null )
- {
- $field_obj = core\JustFieldFactory::create($this);
- $field_index = core\JustFieldFactory::createFieldIndex($field_obj->idBase);
+ public function save( $import = null ) {
+ $field_obj = core\JustFieldFactory::create( $this );
+ $field_index = core\JustFieldFactory::create_field_index( $field_obj->id_base );
- return $field_obj->doUpdate($field_index, $import);
+ return $field_obj->do_update( $field_index, $import );
}
/**
* Delete field with $this->_request params
+ *
* @return boolean
*/
- public function delete()
- {
- $field_obj = core\JustFieldFactory::create($this);
+ public function delete() {
+ $field_obj = core\JustFieldFactory::create( $this );
- return $field_obj->doDelete();
+ return $field_obj->do_delete();
}
/**
* Sort fields with $this->_request params
+ *
* @return boolean
*/
- public function sort()
- {
- $order = trim($this->fields_order, ',');
- $fieldsets = $this->_dL->getFieldsets();
- $new_fields = explode(',', $order);
- $fieldsets[$this->post_type][$this->fieldset_id]['fields'] = array();
+ public function sort() {
+ $order = trim( $this->fields_order, ',' );
+ $fieldsets = $this->_dl->get_fieldsets();
+ $new_fields = explode( ',', $order );
+ $fieldsets[ $this->post_type ][ $this->fieldset_id ]['fields'] = array();
foreach ( $new_fields as $field_id ) {
- $fieldsets[$this->post_type][$this->fieldset_id]['fields'][$field_id] = $field_id;
+ $fieldsets[ $this->post_type ][ $this->fieldset_id ]['fields'][ $field_id ] = $field_id;
}
- $this->_dL->setFieldsets($fieldsets);
+ $this->_dl->set_fieldsets( $fieldsets );
+
+ if ( ! $this->_dl->save_fieldsets_data() ) {
+ $this->add_error( __( 'Sorting isn\'t changed.', 'jcf' ) );
- if ( !$this->_dL->saveFieldsetsData() ) {
- $this->addError(__('Sorting isn\'t changed.', \JustCustomFields::TEXTDOMAIN));
return false;
}
@@ -108,45 +159,48 @@ public function sort()
/**
* Sort sollection fields with $this->_request params
+ *
* @return boolean
*/
- public function sortCollection()
- {
- $fields = $this->_dL->getFields();
- $order = trim($this->fields_order, ',');
- $new_sort = explode(',', $order);
+ public function sort_collection() {
+ $fields = $this->_dl->get_fields();
+ $order = trim( $this->fields_order, ',' );
+ $new_sort = explode( ',', $order );
$new_fields = array();
- if ( !empty($new_sort) ) {
+ if ( ! empty( $new_sort ) ) {
foreach ( $new_sort as $field_id ) {
- if ( isset($fields[$this->post_type][$this->collection_id]['fields'][$field_id]) ) {
- $new_fields[$field_id] = $fields[$this->post_type][$this->collection_id]['fields'][$field_id];
+ if ( isset( $fields[ $this->post_type ][ $this->collection_id ]['fields'][ $field_id ] ) ) {
+ $new_fields[ $field_id ] = $fields[ $this->post_type ][ $this->collection_id ]['fields'][ $field_id ];
}
}
}
- $fields[$this->post_type][$this->collection_id]['fields'] = $new_fields;
- $this->_dL->setFields($fields);
+ $fields[ $this->post_type ][ $this->collection_id ]['fields'] = $new_fields;
+ $this->_dl->set_fields( $fields );
+
+ if ( ! $this->_dl->save_fields_data() ) {
+ $this->add_error( __( 'Sorting isn\'t changed.', 'jcf' ) );
- if ( !$this->_dL->saveFieldsData() ) {
- $this->addError(__('Sorting isn\'t changed.', \JustCustomFields::TEXTDOMAIN));
return false;
}
+
return true;
}
/**
* Check what post type kind of given post type ID
*
- * @param string $post_type Post type ID or Prefixed taxonomy ID
+ * @param string $post_type Post type ID or Prefixed taxonomy ID.
+ *
* @return string
*/
- public static function getPostTypeKind( $post_type )
- {
+ public static function get_post_type_kind( $post_type ) {
$kind = JustField::POSTTYPE_KIND_POST;
- if ( 0 === strpos($post_type, JustField::POSTTYPE_KIND_PREFIX_TAXONOMY) ) {
+ if ( 0 === strpos( $post_type, JustField::POSTTYPE_KIND_PREFIX_TAXONOMY ) ) {
$kind = JustField::POSTTYPE_KIND_TAXONOMY;
}
+
return $kind;
}
diff --git a/models/Fieldset.php b/models/Fieldset.php
index 9dc62eb..dd6ba40 100755
--- a/models/Fieldset.php
+++ b/models/Fieldset.php
@@ -5,8 +5,10 @@
use jcf\core;
use jcf\models;
-class Fieldset extends core\Model
-{
+/**
+ * Class Fieldset
+ */
+class Fieldset extends core\Model {
const POSITION_ADVANCED = 'advanced';
const POSITION_SIDE = 'side';
const POSITION_NORMAL = 'normal';
@@ -15,64 +17,103 @@ class Fieldset extends core\Model
const PRIO_HIGH = 'high';
const PRIO_LOW = 'low';
+ /**
+ * Title
+ *
+ * @var $title
+ */
public $title;
+
+ /**
+ * Post type
+ *
+ * @var $post_type
+ */
public $post_type;
+
+ /**
+ * Fieldset ID
+ *
+ * @var $fieldset_id
+ */
public $fieldset_id;
+
+ /**
+ * Fieldset order
+ *
+ * @var $fieldsets_order
+ */
public $fieldsets_order;
+
+ /**
+ * Position
+ *
+ * @var $position
+ */
public $position;
+
+ /**
+ * Priority
+ *
+ * @var $priority
+ */
public $priority;
/**
* Return number of registered fields and fieldsets for specific post type
+ *
* @return array
*/
- public function getFieldsCounter()
- {
- $fields = $this->_dL->getFields();
- $fieldsets = $this->_dL->getFieldsets();
+ public function get_fields_counter() {
+ $fields = $this->_dl->get_fields();
+ $fieldsets = $this->_dl->get_fieldsets();
$post_types = jcf_get_post_types();
$taxonomies = jcf_get_taxonomies();
foreach ( $post_types as $key => $post_type ) {
$pt = $post_type->name;
- $count[$pt] = array(
+ $count[ $pt ] = array(
'fieldsets' => 0,
- 'fields' => 0,
+ 'fields' => 0,
);
- if ( empty($fields[$pt]) ) continue;
+ if ( empty( $fields[ $pt ] ) ) {
+ continue;
+ }
- $field_keys = array_keys($fields[$pt]);
+ $field_keys = array_keys( $fields[ $pt ] );
- if ( !empty($fieldsets[$pt]) ) {
- $count[$pt]['fieldsets'] = count($fieldsets[$pt]);
+ if ( ! empty( $fieldsets[ $pt ] ) ) {
+ $count[ $pt ]['fieldsets'] = count( $fieldsets[ $pt ] );
- foreach ($fieldsets[$pt] as $fieldset) {
- $fieldset_fields = array_keys($fieldset['fields']);
- $live_fields = array_intersect($fieldset_fields, $field_keys);
- $count[$pt]['fields'] += count($live_fields);
+ foreach ( $fieldsets[ $pt ] as $fieldset ) {
+ $fieldset_fields = array_keys( $fieldset['fields'] );
+ $live_fields = array_intersect( $fieldset_fields, $field_keys );
+ $count[ $pt ]['fields'] += count( $live_fields );
}
}
}
-
+
foreach ( $taxonomies as $tax_key => $taxonomy ) {
- $count[$tax_key] = array(
+ $count[ $tax_key ] = array(
'fieldsets' => 0,
- 'fields' => 0,
+ 'fields' => 0,
);
- if ( empty($fields[$tax_key]) ) continue;
+ if ( empty( $fields[ $tax_key ] ) ) {
+ continue;
+ }
- $field_keys = array_keys($fields[$tax_key]);
+ $field_keys = array_keys( $fields[ $tax_key ] );
- if ( !empty($fieldsets[$tax_key]) ) {
- $count[$tax_key]['fieldsets'] = count($fieldsets[$tax_key]);
+ if ( ! empty( $fieldsets[ $tax_key ] ) ) {
+ $count[ $tax_key ]['fieldsets'] = count( $fieldsets[ $tax_key ] );
- foreach ($fieldsets[$tax_key] as $fieldset) {
- $fieldset_fields = array_keys($fieldset['fields']);
- $live_fields = array_intersect($fieldset_fields, $field_keys);
- $count[$tax_key]['fields'] += count($live_fields);
+ foreach ( $fieldsets[ $tax_key ] as $fieldset ) {
+ $fieldset_fields = array_keys( $fieldset['fields'] );
+ $live_fields = array_intersect( $fieldset_fields, $field_keys );
+ $count[ $tax_key ]['fields'] += count( $live_fields );
}
}
}
@@ -82,135 +123,147 @@ public function getFieldsCounter()
/**
* Get fields and fieldsets by post_type
- * @param string $post_type Name post type
+ *
+ * @param string $post_type Name post type.
+ *
* @return array
*/
- public function findByPostType( $post_type )
- {
- $fieldsets = $this->_dL->getFieldsets();
- if ( !empty($fieldsets[$post_type]) )
- return $fieldsets[$post_type];
+ public function find_by_post_type( $post_type ) {
+ $fieldsets = $this->_dl->get_fieldsets();
+ if ( ! empty( $fieldsets[ $post_type ] ) ) {
+ return $fieldsets[ $post_type ];
+ }
return array();
}
/**
* Get all fieldsets
+ *
* @return array
*/
- public function findAll()
- {
- return $this->_dL->getFieldsets();
+ public function find_all() {
+ return $this->_dl->get_fieldsets();
}
/**
* Get fieldset by ID
- * @param string $fieldset_id
+ *
+ * @param string $fieldset_id Fieldset ID.
+ *
* @return array
*/
- public function findById( $fieldset_id )
- {
- $fieldsets = $this->_dL->getFieldsets();
- if ( empty($fieldsets[$this->post_type][$fieldset_id]) ) {
- $this->addError(__('Fieldset not found', \JustCustomFields::TEXTDOMAIN));
+ public function find_by_id( $fieldset_id ) {
+ $fieldsets = $this->_dl->get_fieldsets();
+ if ( empty( $fieldsets[ $this->post_type ][ $fieldset_id ] ) ) {
+ $this->add_error( __( 'Fieldset not found', 'jcf' ) );
+
return false;
}
- return $fieldsets[$this->post_type][$fieldset_id];
+
+ return $fieldsets[ $this->post_type ][ $fieldset_id ];
}
/**
* Create new fieldset with $this->_request params
+ *
* @return boolean
*/
- public function create()
- {
- if ( empty($this->title) && empty($this->import_data) ) {
- $this->addError(__('Title field is required.', \JustCustomFields::TEXTDOMAIN));
+ public function create() {
+ if ( empty( $this->title ) && empty( $this->import_data ) ) {
+ $this->add_error( __( 'Title field is required.', 'jcf' ) );
+
return false;
}
- $slug = $this->createSlug();
+ $slug = $this->create_slug();
- $fieldsets = $this->_dL->getFieldsets();
+ $fieldsets = $this->_dl->get_fieldsets();
+
+ // check exists.
+ if ( isset( $fieldsets[ $this->post_type ][ $slug ] ) ) {
+ $this->add_error( __( 'Such fieldset already exists.', 'jcf' ) );
- // check exists
- if ( isset($fieldsets[$this->post_type][$slug]) ) {
- $this->addError(__('Such fieldset already exists.', \JustCustomFields::TEXTDOMAIN));
return false;
}
- $fieldsets[$this->post_type][$slug] = array(
- 'id' => $slug,
- 'title' => $this->title,
+ $fieldsets[ $this->post_type ][ $slug ] = array(
+ 'id' => $slug,
+ 'title' => $this->title,
'position' => $this->position,
'priority' => $this->priority,
- 'fields' => array()
+ 'fields' => array(),
);
- return $this->_save($fieldsets);
+ return $this->_save( $fieldsets );
}
/**
* Delete fieldset with $this->_request params
+ *
* @return boolean
*/
- public function delete()
- {
- if ( empty($this->fieldset_id) ) {
- $this->addError(__('Wrong params passed.', \JustCustomFields::TEXTDOMAIN));
+ public function delete() {
+ if ( empty( $this->fieldset_id ) ) {
+ $this->add_error( __( 'Wrong params passed.', 'jcf' ) );
+
return false;
}
- $fieldsets = $this->_dL->getFieldsets();
- if ( isset($fieldsets[$this->post_type][$this->fieldset_id]) )
- unset($fieldsets[$this->post_type][$this->fieldset_id]);
+ $fieldsets = $this->_dl->get_fieldsets();
+ if ( isset( $fieldsets[ $this->post_type ][ $this->fieldset_id ] ) ) {
+ unset( $fieldsets[ $this->post_type ][ $this->fieldset_id ] );
+ }
- return $this->_save($fieldsets);
+ return $this->_save( $fieldsets );
}
/**
* Update fieldset with $this->_request params
+ *
* @return boolean
*/
- public function update()
- {
- $fieldsets = $this->_dL->getFieldsets();
+ public function update() {
+ $fieldsets = $this->_dl->get_fieldsets();
+
+ if ( empty( $fieldsets[ $this->post_type ][ $this->fieldset_id ] ) ) {
+ $this->add_error( __( 'Wrong data passed.', 'jcf' ) );
- if ( empty($fieldsets[$this->post_type][$this->fieldset_id]) ) {
- $this->addError(__('Wrong data passed.', \JustCustomFields::TEXTDOMAIN));
return false;
}
- if ( empty($this->title) ) {
- $this->addError(__('Title field is required.', \JustCustomFields::TEXTDOMAIN));
+ if ( empty( $this->title ) ) {
+ $this->add_error( __( 'Title field is required.', 'jcf' ) );
+
return false;
}
- $fieldsets[$this->post_type][$this->fieldset_id]['title'] = $this->title;
- $fieldsets[$this->post_type][$this->fieldset_id]['position'] = $this->position;
- $fieldsets[$this->post_type][$this->fieldset_id]['priority'] = $this->priority;
+ $fieldsets[ $this->post_type ][ $this->fieldset_id ]['title'] = $this->title;
+ $fieldsets[ $this->post_type ][ $this->fieldset_id ]['position'] = $this->position;
+ $fieldsets[ $this->post_type ][ $this->fieldset_id ]['priority'] = $this->priority;
- return $this->_save($fieldsets);
+ return $this->_save( $fieldsets );
}
/**
* Sort fieldsets with $this->_request params
+ *
* @return boolean
*/
- public function sort()
- {
- $sort = explode(',', trim($this->fieldsets_order, ','));
- $fieldsets = $this->_dL->getFieldsets();
+ public function sort() {
+ $sort = explode( ',', trim( $this->fieldsets_order, ',' ) );
+ $fieldsets = $this->_dl->get_fieldsets();
$ordered_fieldsets = array();
foreach ( $sort as $key ) {
- $ordered_fieldsets[$key] = $fieldsets[$this->post_type][$key];
+ $ordered_fieldsets[ $key ] = $fieldsets[ $this->post_type ][ $key ];
}
- $fieldsets[$this->post_type] = $ordered_fieldsets;
+ $fieldsets[ $this->post_type ] = $ordered_fieldsets;
+
+ if ( ! $this->_save( $fieldsets ) ) {
+ $this->add_error( __( 'Sorting isn\'t changed.', 'jcf' ) );
- if ( !$this->_save($fieldsets) ) {
- $this->addError(__('Sorting isn\'t changed.', \JustCustomFields::TEXTDOMAIN));
return false;
}
@@ -219,42 +272,44 @@ public function sort()
/**
* Create slug for new fieldset
+ *
* @return string
*/
- public function createSlug()
- {
- $slug = preg_replace('/[^a-z0-9\-\_\s]/i', '', $this->title);
- $trimed_slug = trim($slug);
+ public function create_slug() {
+ $slug = preg_replace( '/[^a-z0-9\-\_\s]/i', '', $this->title );
+ $trimed_slug = trim( $slug );
if ( $trimed_slug == '' ) {
- $slug = 'jcf-fieldset-' . rand(0, 10000);
- }
- else {
- $slug = sanitize_title($this->title);
+ $slug = 'jcf-fieldset-' . rand( 0, 10000 );
+ } else {
+ $slug = sanitize_title( $this->title );
}
+
return $slug;
}
/**
* Save fieldsets
- * @param array $fieldsets
+ *
+ * @param array $fieldsets Fieldsets.
+ *
* @return boolean
*/
- protected function _save( $fieldsets )
- {
- $this->_dL->setFieldsets($fieldsets);
- $save = $this->_dL->saveFieldsetsData();
- return !empty($save);
+ protected function _save( $fieldsets ) {
+ $this->_dl->set_fieldsets( $fieldsets );
+ $save = $this->_dl->save_fieldsets_data();
+
+ return ! empty( $save );
}
/**
* Check what post type kind of given post type ID
*
- * @param string $post_type Post type ID or Prefixed taxonomy ID
+ * @param string $post_type Post type ID or Prefixed taxonomy ID.
+ *
* @return string
*/
- public static function getPostTypeKind( $post_type )
- {
- return Field::getPostTypeKind( $post_type );
+ public static function get_post_type_kind( $post_type ) {
+ return Field::get_post_type_kind( $post_type );
}
}
diff --git a/models/FieldsetVisibility.php b/models/FieldsetVisibility.php
index 03ba882..1ade06f 100644
--- a/models/FieldsetVisibility.php
+++ b/models/FieldsetVisibility.php
@@ -5,8 +5,10 @@
use jcf\core;
use jcf\models;
-class FieldsetVisibility extends core\Model
-{
+/**
+ * Class FieldsetVisibility
+ */
+class FieldsetVisibility extends core\Model {
const SCENARIO_CREATE = 'create';
const SCENARIO_UPDATE = 'update';
@@ -19,96 +21,159 @@ class FieldsetVisibility extends core\Model
const JOIN_AND = 'and';
const JOIN_OR = 'or';
+ /**
+ * Scenario
+ *
+ * @var $scenario
+ */
public $scenario = false;
+
+ /**
+ * Post type
+ *
+ * @var $post_type
+ */
public $post_type;
+
+ /**
+ * Based On
+ *
+ * @var $based_on
+ */
public $based_on;
+
+ /**
+ * Fieldset ID
+ *
+ * @var $fieldset_id
+ */
public $fieldset_id;
+
+ /**
+ * Rule ID
+ *
+ * @var $rule_id
+ */
public $rule_id;
+
+ /**
+ * Rule
+ *
+ * @var $rule
+ */
public $rule;
+
+ /**
+ * Rule data
+ *
+ * @var $rule_data
+ */
public $rule_data;
+
+ /**
+ * Taxonomy
+ *
+ * @var $taxonomy
+ */
public $taxonomy;
+
+ /**
+ * Term
+ *
+ * @var $term
+ */
public $term;
/**
* Get visibility rules by post type
- * @param string $post_type
+ *
+ * @param string $post_type Post type.
+ *
* @return array
*/
- public function findByPostType($post_type)
- {
- $fieldsets = $this->_dL->getFieldsets();
+ public function find_by_post_type( $post_type ) {
+ $fieldsets = $this->_dl->get_fieldsets();
$visibility_rules = array();
- if ( empty($fieldsets[$post_type]) ) return;
+ if ( empty( $fieldsets[ $post_type ] ) ) {
+ return;
+ }
- foreach ($fieldsets[$post_type] as $f_id => $fieldset) {
+ foreach ( $fieldsets[ $post_type ] as $f_id => $fieldset ) {
- if ( empty($fieldset['visibility_rules']) ) continue;
+ if ( empty( $fieldset['visibility_rules'] ) ) {
+ continue;
+ }
- $visibility_rules[$f_id] = array_values($fieldset['visibility_rules']);
+ $visibility_rules[ $f_id ] = array_values( $fieldset['visibility_rules'] );
- foreach ( $visibility_rules[$f_id] as $key => $rule ) {
- if ( $rule['based_on'] !== self::BASEDON_TAXONOMY ) continue;
+ foreach ( $visibility_rules[ $f_id ] as $key => $rule ) {
+ if ( self::BASEDON_TAXONOMY !== $rule['based_on'] ) {
+ continue;
+ }
$taxonomy = get_taxonomy( $rule['rule_taxonomy'] );
- if ( empty($taxonomy) ) {
- unset($visibility_rules[$f_id][$key]);
+ if ( empty( $taxonomy ) ) {
+ unset( $visibility_rules[ $f_id ][ $key ] );
continue;
}
- $taxo_terms = array();
- $taxo_term_ids = array();
+ $taxo_terms = array();
+ $taxo_term_ids = array();
$taxo_term_names = array();
foreach ( $rule['rule_taxonomy_terms'] as $term_id ) {
- /* @var $term \WP_Term */
- $term = get_term_by('id', $term_id, $rule['rule_taxonomy']);
- if ( empty($term) ) continue;
+ $term = get_term_by( 'id', $term_id, $rule['rule_taxonomy'] );
+ if ( empty( $term ) ) {
+ continue;
+ }
- $taxo_terms[] = $term;
- $taxo_term_ids[] = $term_id;
+ $taxo_terms[] = $term;
+ $taxo_term_ids[] = $term_id;
$taxo_term_names[] = $term->name;
}
- $visibility_rules[$f_id][$key]['taxonomy'] = $taxonomy;
- $visibility_rules[$f_id][$key]['terms'] = $taxo_terms;
- $visibility_rules[$f_id][$key]['term_ids'] = $taxo_term_ids;
- $visibility_rules[$f_id][$key]['term_names'] = $taxo_term_names;
+ $visibility_rules[ $f_id ][ $key ]['taxonomy'] = $taxonomy;
+ $visibility_rules[ $f_id ][ $key ]['terms'] = $taxo_terms;
+ $visibility_rules[ $f_id ][ $key ]['term_ids'] = $taxo_term_ids;
+ $visibility_rules[ $f_id ][ $key ]['term_names'] = $taxo_term_names;
}
}
+
return $visibility_rules;
}
/**
* Get form data for visibility rules form
+ *
* @return array
*/
- public function getForm()
- {
- $output = array();
- $taxonomies = get_object_taxonomies($this->post_type, 'objects');
- $templates = jcf_get_page_templates($this->post_type);
+ public function get_form() {
+ $output = array();
+ $taxonomies = get_object_taxonomies( $this->post_type, 'objects' );
+ $templates = jcf_get_page_templates( $this->post_type );
- $output['post_type'] = $this->post_type;
+ $output['post_type'] = $this->post_type;
$output['taxonomies'] = $taxonomies;
- $output['scenario'] = $this->scenario;
- $output['templates'] = $templates;
+ $output['scenario'] = $this->scenario;
+ $output['templates'] = $templates;
+
+ if ( ! empty( $this->scenario ) && self::SCENARIO_UPDATE === $this->scenario ) {
- if ( !empty($this->scenario) && $this->scenario == self::SCENARIO_UPDATE ) {
+ $visibility_rule = $this->_get_fieldset_visibility( $this->fieldset_id, $this->rule_id );
- $visibility_rule = $this->_getFieldsetVisibility($this->fieldset_id, $this->rule_id);
+ if ( empty( $visibility_rule ) ) {
+ $this->add_error( __( 'Visibility rule not found.', 'jcf' ) );
- if ( empty($visibility_rule) ) {
- $this->addError(__('Visibility rule not found.', \JustCustomFields::TEXTDOMAIN));
return false;
}
- if ( $visibility_rule['based_on'] == self::BASEDON_TAXONOMY ) {
- $terms = get_terms($visibility_rule['rule_taxonomy'], array( 'hide_empty' => false ));
+ if ( self::BASEDON_TAXONOMY === $visibility_rule['based_on'] ) {
+ $terms = get_terms( $visibility_rule['rule_taxonomy'], array( 'hide_empty' => false ) );
$output['terms'] = $terms;
}
- $output['rule_id'] = $this->rule_id;
- $output['fieldset_id'] = $this->fieldset_id;
+ $output['rule_id'] = $this->rule_id;
+ $output['fieldset_id'] = $this->fieldset_id;
$output['visibility_rule'] = $visibility_rule;
}
@@ -117,15 +182,14 @@ public function getForm()
/**
* Get visibility rules for fieldset with $this->_request
+ *
* @return array
*/
- public function getBasedOnOptions()
- {
- if ( $this->based_on == self::BASEDON_PAGE_TPL ) {
- $options = jcf_get_page_templates($this->post_type);
- }
- else {
- $options = get_object_taxonomies($this->post_type, 'objects');
+ public function get_based_on_options() {
+ if ( self::BASEDON_PAGE_TPL === $this->based_on ) {
+ $options = jcf_get_page_templates( $this->post_type );
+ } else {
+ $options = get_object_taxonomies( $this->post_type, 'objects' );
}
return $options;
@@ -133,20 +197,23 @@ public function getBasedOnOptions()
/**
* Save visibility rule
+ *
* @return array|boolean
*/
- public function update()
- {
- $visibility_rules = $this->_getFieldsetVisibility($this->fieldset_id);
+ public function update() {
+ $visibility_rules = $this->_get_fieldset_visibility( $this->fieldset_id );
- if ( empty($this->rule_id) ) $this->rule_id = time();
+ if ( empty( $this->rule_id ) ) {
+ $this->rule_id = time();
+ }
- $this->rule_data['rule_id'] = $this->rule_id;
- $visibility_rules[$this->rule_id] = $this->rule_data;
+ $this->rule_data['rule_id'] = $this->rule_id;
+ $visibility_rules[ $this->rule_id ] = $this->rule_data;
+
+ $saved = $this->_save_fieldset_visibility( $this->fieldset_id, $visibility_rules );
+ if ( ! $saved ) {
+ $this->add_error( __( 'Visibility rule not updated.', 'jcf' ) );
- $saved = $this->_saveFieldsetVisibility($this->fieldset_id, $visibility_rules);
- if ( !$saved ) {
- $this->addError(__('Visibility rule not updated.', \JustCustomFields::TEXTDOMAIN));
return false;
}
@@ -155,47 +222,50 @@ public function update()
/**
* Delete visibility rule
+ *
* @return array|boolean
*/
- public function delete()
- {
- $visibility_rules = $this->_getFieldsetVisibility($this->fieldset_id);
- if ( isset($visibility_rules[$this->rule_id]) )
- unset($visibility_rules[$this->rule_id]);
-
- $saved = $this->_saveFieldsetVisibility($this->fieldset_id, $visibility_rules);
- if ( !$saved ) {
- $this->addError(__('Visibility rule not deleted.', \JustCustomFields::TEXTDOMAIN));
+ public function delete() {
+ $visibility_rules = $this->_get_fieldset_visibility( $this->fieldset_id );
+ if ( isset( $visibility_rules[ $this->rule_id ] ) ) {
+ unset( $visibility_rules[ $this->rule_id ] );
+ }
+
+ $saved = $this->_save_fieldset_visibility( $this->fieldset_id, $visibility_rules );
+ if ( ! $saved ) {
+ $this->add_error( __( 'Visibility rule not deleted.', 'jcf' ) );
+
return false;
}
- return !empty($visibility_rules) ? $visibility_rules : true;
+ return ! empty( $visibility_rules ) ? $visibility_rules : true;
}
/**
* Autocomplete for visibility rule
- * @param string $taxonomy
- * @param string $term
+ *
+ * @param string $taxonomy Taxonomy.
+ * @param string $term Term.
+ *
* @global \WPDB $wpdb
* @return array
*/
- public static function findTaxonomyTerms($taxonomy, $term)
- {
+ public static function find_taxonomy_terms( $taxonomy, $term ) {
global $wpdb;
- $query = "SELECT t.term_id, t.name
+ $query = "SELECT t.term_id, t.name
FROM $wpdb->terms AS t
LEFT JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id
WHERE t.name LIKE '%$term%' AND tt.taxonomy = '$taxonomy'";
- $terms = $wpdb->get_results($query);
+ $terms = $wpdb->get_results( $query );
$response = array();
foreach ( $terms as $p ) {
$response[] = array(
- 'id' => $p->term_id,
- 'label' => $p->name,
- 'value' => $p->name,
- 'status' => true
+ 'id' => $p->term_id,
+ 'label' => $p->name,
+ 'value' => $p->name,
+ 'status' => true,
);
}
@@ -206,25 +276,26 @@ public static function findTaxonomyTerms($taxonomy, $term)
* Get visibility rules for fieldset $fieldset_id
* Use current model post_type
*
- * @param string $fieldset_id
- * @param integer|null $rule_id
+ * @param string $fieldset_id Fiedlset ID.
+ * @param integer|null $rule_id Rule ID.
+ *
* @return mixed
*/
- protected function _getFieldsetVisibility( $fieldset_id, $rule_id = null )
- {
- $fieldsets = $this->_dL->getFieldsets();
-
- // if we take only fieldset settings - return it
- if ( is_null($rule_id) ) {
- if ( isset($fieldsets[$this->post_type][$fieldset_id]['visibility_rules']) )
- return $fieldsets[$this->post_type][$fieldset_id]['visibility_rules'];
+ protected function _get_fieldset_visibility( $fieldset_id, $rule_id = null ) {
+ $fieldsets = $this->_dl->get_fieldsets();
+
+ // if we take only fieldset settings - return it.
+ if ( is_null( $rule_id ) ) {
+ if ( isset( $fieldsets[ $this->post_type ][ $fieldset_id ]['visibility_rules'] ) ) {
+ return $fieldsets[ $this->post_type ][ $fieldset_id ]['visibility_rules'];
+ }
}
- // if we search for some specific rule
- if ( !is_null($rule_id)
- && isset($fieldsets[$this->post_type][$fieldset_id]['visibility_rules'][$rule_id])
+ // if we search for some specific rule.
+ if ( ! is_null( $rule_id )
+ && isset( $fieldsets[ $this->post_type ][ $fieldset_id ]['visibility_rules'][ $rule_id ] )
) {
- return $fieldsets[$this->post_type][$fieldset_id]['visibility_rules'][$rule_id];
+ return $fieldsets[ $this->post_type ][ $fieldset_id ]['visibility_rules'][ $rule_id ];
}
return array();
@@ -234,27 +305,31 @@ protected function _getFieldsetVisibility( $fieldset_id, $rule_id = null )
* Save visibility rules for fieldset $fieldset_id
* Use current model post_type
*
- * @param string $fieldset_id
+ * @param string $fieldset_id Fieldset ID.
+ * @param string $rules Rules.
+ *
* @return boolean
*/
- protected function _saveFieldsetVisibility( $fieldset_id, $rules )
- {
- $fieldsets = $this->_dL->getFieldsets();
- $fieldsets[$this->post_type][$fieldset_id]['visibility_rules'] = $rules;
- return $this->_save($fieldsets);
+ protected function _save_fieldset_visibility( $fieldset_id, $rules ) {
+ $fieldsets = $this->_dl->get_fieldsets();
+ $fieldsets[ $this->post_type ][ $fieldset_id ]['visibility_rules'] = $rules;
+
+ return $this->_save( $fieldsets );
}
/**
* Save visibility settings
- * @param array $fieldsets
+ *
+ * @param array $fieldsets Fieldsets.
+ *
* @return boolean
*/
- protected function _save( $fieldsets )
- {
- $this->_dL->setFieldsets($fieldsets);
- $saved = $this->_dL->saveFieldsetsData();
- return !empty($saved);
+ protected function _save( $fieldsets ) {
+ $this->_dl->set_fieldsets( $fieldsets );
+ $saved = $this->_dl->save_fieldsets_data();
+
+ return ! empty( $saved );
}
}
diff --git a/models/FilesDataLayer.php b/models/FilesDataLayer.php
index b67c94e..c059a30 100755
--- a/models/FilesDataLayer.php
+++ b/models/FilesDataLayer.php
@@ -5,9 +5,23 @@
use jcf\core;
use jcf\models;
-class FilesDataLayer extends core\DataLayer
-{
- protected $_sourceSettings;
+/**
+ * Class FilesDataLayer
+ */
+class FilesDataLayer extends core\DataLayer {
+
+ /**
+ * Source Settings
+ *
+ * @var $_source_settings
+ */
+ protected $_source_settings;
+
+ /**
+ * Cache
+ *
+ * @var $_cache
+ */
static private $_cache;
const FIELDS_KEY = 'fields';
@@ -19,118 +33,131 @@ class FilesDataLayer extends core\DataLayer
*
* Init directory source setting to be used in get/update methods
*/
- public function __construct()
- {
- $this->_sourceSettings = models\Settings::getDataSourceType();
+ public function __construct() {
+ $this->_source_settings = models\Settings::get_data_source_type();
parent::__construct();
}
/**
* Set $this->_fields property
- * @param array $fields
+ *
+ * @param array $fields Fields.
+ *
+ * @return bool
*/
- public function setFields( $fields = null )
- {
- if ( !is_null($fields) ) {
+ public function set_fields( $fields = null ) {
+ if ( ! is_null( $fields ) ) {
$this->_fields = $fields;
+
return;
}
- $data = $this->getDataFromFile();
- if ( isset($data[self::FIELDS_KEY]) ) {
- $this->_fields = $data[self::FIELDS_KEY];
+ $data = $this->get_data_from_file();
+ if ( isset( $data[ self::FIELDS_KEY ] ) ) {
+ $this->_fields = $data[ self::FIELDS_KEY ];
}
}
/**
* Update fields
+ *
* @return boolean
*/
- public function saveFieldsData()
- {
- $data = $this->getDataFromFile();
- $data[self::FIELDS_KEY] = $this->_fields;
- return $this->_save($data);
+ public function save_fields_data() {
+ $data = $this->get_data_from_file();
+ $data[ self::FIELDS_KEY ] = $this->_fields;
+
+ return $this->_save( $data );
}
/**
* Get storage version
+ *
* @return array
*/
- public function getStorageVersion()
- {
- $data = $this->getDataFromFile();
- return !empty($data[self::STORAGEVER_KEY]) ? $data[self::STORAGEVER_KEY] : false;
+ public function get_storage_version() {
+ $data = $this->get_data_from_file();
+
+ return ! empty( $data[ self::STORAGEVER_KEY ] ) ? $data[ self::STORAGEVER_KEY ] : false;
}
-
+
/**
* Update storage version
- * @param float|null $version
+ *
+ * @param float|null $version Version.
+ *
* @return boolean
*/
- public function saveStorageVersion($version = null)
- {
- $data = $this->getDataFromFile();
+ public function save_storage_version( $version = null ) {
+ $data = $this->get_data_from_file();
- if ( empty($version) ) {
+ if ( empty( $version ) ) {
$version = \JustCustomFields::VERSION;
}
-
- $data[self::STORAGEVER_KEY] = $version;
- return $this->_save($data);
+
+ $data[ self::STORAGEVER_KEY ] = $version;
+
+ return $this->_save( $data );
}
-
-
+
+
/**
* Get Fieldsets
- * @param array $fieldsets
+ *
+ * @param array $fieldsets Fieldset.
+ *
+ * @return bool
*/
- public function setFieldsets( $fieldsets = null )
- {
- if ( !is_null($fieldsets) ) {
+ public function set_fieldsets( $fieldsets = null ) {
+ if ( ! is_null( $fieldsets ) ) {
$this->_fieldsets = $fieldsets;
+
return;
}
- $data = $this->getDataFromFile();
- if ( isset($data[self::FIELDSETS_KEY]) ) {
- $this->_fieldsets = $data[self::FIELDSETS_KEY];
+ $data = $this->get_data_from_file();
+ if ( isset( $data[ self::FIELDSETS_KEY ] ) ) {
+ $this->_fieldsets = $data[ self::FIELDSETS_KEY ];
}
}
/**
* Save fieldsets
+ *
* @return boolean
*/
- public function saveFieldsetsData()
- {
- $data = $this->getDataFromFile();
- $data[self::FIELDSETS_KEY] = $this->_fieldsets;
- return $this->_save($data);
+ public function save_fieldsets_data() {
+ $data = $this->get_data_from_file();
+ $data[ self::FIELDSETS_KEY ] = $this->_fieldsets;
+
+ return $this->_save( $data );
}
/**
- * Get fields and fieldsets from file
- * @param string $file File name
- * @return boolean/array Array with fields settings from file
+ * Get fields and fieldsets from file
+ *
+ * @param string $file File name.
+ *
+ * @return boolean/array Array with fields settings from file
*/
- public function getDataFromFile( $file = null )
- {
- if ( !$file )
- $file = $this->getConfigFilePath();
-
- if ( file_exists($file) ) {
- $content = file_get_contents($file);
-
- // cache json_decode. on lot of fields it makes a huge load converting this every time
- $cache_hash = md5($content);
- if ( !isset(static::$_cache[$cache_hash]) ) {
- static::$_cache[$cache_hash] = json_decode($content, true);
+ public function get_data_from_file( $file = null ) {
+ if ( ! $file ) {
+ $file = $this->get_config_file_path();
+ }
+
+ if ( file_exists( $file ) ) {
+ $content = file_get_contents( $file );
+
+ // cache json_decode. on lot of fields it makes a huge load converting this every time.
+ $cache_hash = md5( $content );
+ if ( ! isset( static::$_cache[ $cache_hash ] ) ) {
+ static::$_cache[ $cache_hash ] = json_decode( $content, true );
}
- $data = static::$_cache[$cache_hash];
- return gettype($data) == 'string' ? json_decode($data, true) : $data;
+ $data = static::$_cache[ $cache_hash ];
+
+ return gettype( $data ) == 'string' ? json_decode( $data, true ) : $data;
}
return false;
@@ -138,16 +165,17 @@ public function getDataFromFile( $file = null )
/**
* Get path to file with fields and fieldsets
- * @param string $source_settings
+ *
+ * @param string $source_settings Source settings.
+ *
* @return string/boolean
*/
- public function getConfigFilePath( $source_settings = null )
- {
- if ( is_null($source_settings) ) {
- $source_settings = $this->_sourceSettings;
+ public function get_config_file_path( $source_settings = null ) {
+ if ( is_null( $source_settings ) ) {
+ $source_settings = $this->_source_settings;
}
- switch ($source_settings) {
+ switch ( $source_settings ) {
case models\Settings::CONF_SOURCE_FS_THEME:
$path = get_stylesheet_directory() . '/jcf/config.json';
@@ -161,44 +189,46 @@ public function getConfigFilePath( $source_settings = null )
return false;
}
- $path = apply_filters('jcf_config_filepath', $path, $source_settings);
+ $path = apply_filters( 'jcf_config_filepath', $path, $source_settings );
return $path;
}
/**
* Save all field and fieldsets
- * @param array $data
- * @param string $file
+ *
+ * @param array $data Data.
+ * @param string $file File.
+ *
* @return boolean
*/
- protected function _save( $data, $file = null )
- {
- if ( !$file ) {
- $file = $this->getConfigFilePath();
+ protected function _save( $data, $file = null ) {
+ if ( ! $file ) {
+ $file = $this->get_config_file_path();
}
- if ( defined('JSON_PRETTY_PRINT') ) {
- $data = json_encode($data, JSON_PRETTY_PRINT);
- }
- else {
- $data = jcf_format_json(json_encode($data));
+ if ( defined( 'JSON_PRETTY_PRINT' ) ) {
+ $data = json_encode( $data, JSON_PRETTY_PRINT );
+ } else {
+ $data = jcf_format_json( json_encode( $data ) );
}
- $dir = dirname($file);
+ $dir = dirname( $file );
- // trying to create dir
- if ( (!is_dir($dir) && !wp_mkdir_p($dir)) || !is_writable($dir) ) {
+ // trying to create dir.
+ if ( ( ! is_dir( $dir ) && ! wp_mkdir_p( $dir ) ) || ! is_writable( $dir ) ) {
return false;
}
- if ( !empty($dir) ) {
- if ( $fp = fopen($file, 'w') ) {
- fwrite($fp, $data . "\r\n");
- fclose($fp);
- jcf_set_chmod($file);
+ if ( ! empty( $dir ) ) {
+ if ( $fp = fopen( $file, 'w' ) ) {
+ fwrite( $fp, $data . "\r\n" );
+ fclose( $fp );
+ jcf_set_chmod( $file );
+
return true;
}
}
+
return false;
}
diff --git a/models/ImportExport.php b/models/ImportExport.php
index 22369a7..5a4c987 100644
--- a/models/ImportExport.php
+++ b/models/ImportExport.php
@@ -5,29 +5,57 @@
use jcf\core;
use jcf\models;
-class ImportExport extends core\Model
-{
+/**
+ * Class ImportExport
+ */
+class ImportExport extends core\Model {
+
+ /**
+ * Action
+ *
+ * @var $action
+ */
public $action;
+
+ /**
+ * Selected data
+ *
+ * @var $selected_data
+ */
public $selected_data;
+
+ /**
+ * Import Source
+ *
+ * @var $import_source
+ */
public $import_source;
+
+ /**
+ * File name
+ *
+ * @var $file_name
+ */
public $file_name;
/**
* Get fields for import
*/
- public function getImportFields()
- {
- if ( $this->action != 'jcf_import_fields_form' || !$this->validateImportFile() ) return;
+ public function get_import_fields() {
+ if ( 'jcf_import_fields_form' !== $this->action || ! $this->validate_import_file() ) {
+ return;
+ }
- /* @var $files_dL FilesDataLayer */
+ /* @var $files_dl FilesDataLayer */
$import_file = $_FILES['import_data']['tmp_name'];
- $files_dL = core\DataLayerFactory::create('file');
- $data = $files_dL->getDataFromFile( $import_file );
- unlink($import_file);
+ $files_dl = core\DataLayerFactory::create( 'file' );
+ $data = $files_dl->get_data_from_file( $import_file );
+ unlink( $import_file );
+
+ if ( empty( $data['post_types'] ) ) {
+ $error = __( 'IMPORT FAILED! File do not contain fields settings data..', 'jcf' );
+ $this->add_error( $error );
- if ( empty($data['post_types']) ) {
- $error = __('IMPORT FAILED! File do not contain fields settings data..', \JustCustomFields::TEXTDOMAIN);
- $this->addError($error);
return;
}
@@ -40,25 +68,27 @@ public function getImportFields()
*
* @return bool
*/
- public function validateImportFile()
- {
- if ( empty($_FILES['import_data']['name']) ) {
- $error = __('IMPORT FAILED! Import file is missing.', \JustCustomFields::TEXTDOMAIN);
- $this->addError($error);
+ public function validate_import_file() {
+ if ( empty( $_FILES['import_data']['name'] ) ) {
+ $error = __( 'IMPORT FAILED! Import file is missing.', 'jcf' );
+ $this->add_error( $error );
+
return false;
}
- if ( !is_readable($_FILES['import_data']['tmp_name']) ) {
- $error = __('IMPORT FAILED! Can\'t read uploaded file.', \JustCustomFields::TEXTDOMAIN);
- $this->addError($error);
+ if ( ! is_readable( $_FILES['import_data']['tmp_name'] ) ) {
+ $error = __( 'IMPORT FAILED! Can\'t read uploaded file.', 'jcf' );
+ $this->add_error( $error );
+
return false;
}
- $path_info = pathinfo($_FILES['import_data']['name']);
+ $path_info = pathinfo( $_FILES['import_data']['name'] );
+
+ if ( 'json' !== $path_info['extension'] ) {
+ $error = __( 'IMPORT FAILED! Please upload correct file format.', 'jcf' );
+ $this->add_error( $error );
- if ( $path_info['extension'] !== 'json' ) {
- $error = __('IMPORT FAILED! Please upload correct file format.', \JustCustomFields::TEXTDOMAIN);
- $this->addError($error);
return false;
}
@@ -70,69 +100,69 @@ public function validateImportFile()
*
* @return bool|void
*/
- public function import()
- {
- if ( $this->action != 'jcf_import_fields' || empty($this->selected_data) || empty($this->import_source) ) return;
-
- $dl_fields = $this->_dL->getFields();
- $dl_fieldsets = $this->_dL->getFieldsets();
-
- // we take origin import source and remove elements which are not selected
- $import_source = json_decode(stripslashes($this->import_source), true);
- $import_data = $this->_processSelectedData($import_source['fieldsets'], $import_source['fields'], $import_source['post_types']);
-
- // update fieldsets
- foreach ($import_data['fieldsets'] as $cpt_id => $fieldsets) {
- foreach ($fieldsets as $fieldset_id => $fieldset) {
- // if fieldset not exists - just copy it from import data
- if ( !isset($dl_fieldsets[$cpt_id][$fieldset_id]) ) {
- $dl_fieldsets[$cpt_id][$fieldset_id] = $fieldset;
+ public function import() {
+ if ( $this->action != 'jcf_import_fields' || empty( $this->selected_data ) || empty( $this->import_source ) ) {
+ return;
+ }
+
+ $dl_fields = $this->_dl->get_fields();
+ $dl_fieldsets = $this->_dl->get_fieldsets();
+
+ // we take origin import source and remove elements which are not selected.
+ $import_source = json_decode( stripslashes( $this->import_source ), true );
+ $import_data = $this->_process_selected_data( $import_source['fieldsets'], $import_source['fields'], $import_source['post_types'] );
+
+ // update fieldsets.
+ foreach ( $import_data['fieldsets'] as $cpt_id => $fieldsets ) {
+ foreach ( $fieldsets as $fieldset_id => $fieldset ) {
+ // if fieldset not exists - just copy it from import data.
+ if ( ! isset( $dl_fieldsets[ $cpt_id ][ $fieldset_id ] ) ) {
+ $dl_fieldsets[ $cpt_id ][ $fieldset_id ] = $fieldset;
continue;
}
- // for existed fieldset we merge fields list inside the template. All new will be added at the end
- $dl_fieldsets[$cpt_id][$fieldset_id]['fields'] = array_merge(
- $dl_fieldsets[$cpt_id][$fieldset_id]['fields'],
+ // for existed fieldset we merge fields list inside the template. All new will be added at the end.
+ $dl_fieldsets[ $cpt_id ][ $fieldset_id ]['fields'] = array_merge(
+ $dl_fieldsets[ $cpt_id ][ $fieldset_id ]['fields'],
$fieldset['fields']
);
}
}
- // update fields
- foreach ($import_data['fields'] as $cpt_id => $fields) {
- foreach ($fields as $field_id => $field) {
- // if field not exists - just copy it from import data
- if ( !isset($dl_fields[$cpt_id][$field_id]) ) {
- $dl_fields[$cpt_id][$field_id] = $field;
+ // update fields.
+ foreach ( $import_data['fields'] as $cpt_id => $fields ) {
+ foreach ( $fields as $field_id => $field ) {
+ // if field not exists - just copy it from import data.
+ if ( ! isset( $dl_fields[ $cpt_id ][ $field_id ] ) ) {
+ $dl_fields[ $cpt_id ][ $field_id ] = $field;
continue;
}
- // for existed field we merge collection fields first
- if ( preg_match('/^collection/', $field_id) ) {
+ // for existed field we merge collection fields first.
+ if ( preg_match( '/^collection/', $field_id ) ) {
$field['fields'] = array_merge(
- $dl_fields[$cpt_id][$field_id]['fields'],
+ $dl_fields[ $cpt_id ][ $field_id ]['fields'],
$field['fields']
);
}
- // not merge all settings
- $dl_fields[$cpt_id][$field_id] = array_merge(
- $dl_fields[$cpt_id][$field_id],
+ // not merge all settings.
+ $dl_fields[ $cpt_id ][ $field_id ] = array_merge(
+ $dl_fields[ $cpt_id ][ $field_id ],
$field
);
}
}
- // save to data layer
- $this->_dL->setFields($dl_fields);
- $this->_dL->setFieldsets($dl_fieldsets);
- $import_status = $this->_dL->saveFieldsData() && $this->_dL->saveFieldsetsData();
+ // save to data layer.
+ $this->_dl->set_fields( $dl_fields );
+ $this->_dl->set_fieldsets( $dl_fieldsets );
+ $import_status = $this->_dl->save_fields_data() && $this->_dl->save_fieldsets_data();
if ( $import_status ) {
- $this->addMessage(__('Import has been completed successfully!', \JustCustomFields::TEXTDOMAIN));
- }
- else {
- $this->addError(__('Import failed! Please check that your import file has right format.', \JustCustomFields::TEXTDOMAIN));
+ $this->add_message( __( 'Import has been completed successfully!', 'jcf' ) );
+ } else {
+ $this->add_error( __( 'Import failed! Please check that your import file has right format.', 'jcf' ) );
}
return $import_status;
@@ -143,75 +173,72 @@ public function import()
*
* @return array
*/
- public function export()
- {
- if ( empty($this->selected_data) || !is_array($this->selected_data) ) {
- $this->addError(__('Export failed! Please select fields to export.', \JustCustomFields::TEXTDOMAIN));
+ public function export() {
+ if ( empty( $this->selected_data ) || ! is_array( $this->selected_data ) ) {
+ $this->add_error( __( 'Export failed! Please select fields to export.', 'jcf' ) );
+
return array();
}
$fieldsets_model = new models\Fieldset();
- $fieldsets_data = $fieldsets_model->findAll();
+ $fieldsets_data = $fieldsets_model->find_all();
$fields_model = new models\Field();
- $fields_data = $fields_model->findAll();
+ $fields_data = $fields_model->find_all();
$post_types = jcf_get_post_types();
- $data = $this->_processSelectedData($fieldsets_data, $fields_data, $post_types);
+ $data = $this->_process_selected_data( $fieldsets_data, $fields_data, $post_types );
- //pa($data,1);
return $data;
}
/**
* Build clean settings arrays based on selected params
*
- * @param array $fieldsets_data
- * @param array $fields_data
- * @param array $post_types
+ * @param array $fieldsets_data Fieldsets data.
+ * @param array $fields_data Fields data.
+ * @param array $post_types Post types.
+ *
* @return array
*/
- protected function _processSelectedData(array $fieldsets_data, array $fields_data, array $post_types)
- {
+ protected function _process_selected_data( array $fieldsets_data, array $fields_data, array $post_types ) {
$data = array(
- 'fieldsets' => array(),
- 'fields' => array(),
+ 'fieldsets' => array(),
+ 'fields' => array(),
'post_types' => array(),
);
- foreach ($this->selected_data as $cpt_id => $fieldsets) {
- $data['post_types'][$cpt_id] = $post_types[$cpt_id];
+ foreach ( $this->selected_data as $cpt_id => $fieldsets ) {
+ $data['post_types'][ $cpt_id ] = $post_types[ $cpt_id ];
- foreach ($fieldsets as $fieldset_id => $fieldset) {
- $fieldset = array_merge($fieldsets_data[$cpt_id][$fieldset_id], $fieldset);
+ foreach ( $fieldsets as $fieldset_id => $fieldset ) {
+ $fieldset = array_merge( $fieldsets_data[ $cpt_id ][ $fieldset_id ], $fieldset );
foreach ( $fieldset['fields'] as $field_id => $field_params ) {
- // if not collection - simple copy field settings
- if ( !preg_match('/^collection/', $field_id) ) {
- $field = $fields_data[$cpt_id][$field_id];
- }
- // for collection we define which one fields we should disable
+ // if not collection - simple copy field settings.
+ if ( ! preg_match( '/^collection/', $field_id ) ) {
+ $field = $fields_data[ $cpt_id ][ $field_id ];
+ } // for collection we define which one fields we should disable
else {
- $collection = $fields_data[$cpt_id][$field_id];
+ $collection = $fields_data[ $cpt_id ][ $field_id ];
$collection_fields = array();
- if ( !empty($field_params['collection_fields']) ) {
- foreach ($field_params['collection_fields'] as $collection_field_id => $is_exported) {
- $collection_fields[$collection_field_id] = $collection['fields'][$collection_field_id];
+ if ( ! empty( $field_params['collection_fields'] ) ) {
+ foreach ( $field_params['collection_fields'] as $collection_field_id => $is_exported ) {
+ $collection_fields[ $collection_field_id ] = $collection['fields'][ $collection_field_id ];
}
}
- $field = array_merge($collection, array('fields' => $collection_fields));
+ $field = array_merge( $collection, array( 'fields' => $collection_fields ) );
}
- $fieldset['fields'][$field_id] = 1;
- $data['fields'][$cpt_id][$field_id] = $field;
+ $fieldset['fields'][ $field_id ] = 1;
+ $data['fields'][ $cpt_id ][ $field_id ] = $field;
}
- $data['fieldsets'][$cpt_id][$fieldset_id] = $fieldset;
+ $data['fieldsets'][ $cpt_id ][ $fieldset_id ] = $fieldset;
}
}
- //pa($data,1);
return $data;
}
}
diff --git a/models/Migrate.php b/models/Migrate.php
index e0a4853..745eae3 100644
--- a/models/Migrate.php
+++ b/models/Migrate.php
@@ -1,12 +1,15 @@
load()
@@ -18,13 +21,12 @@ class Migrate extends Model
/**
* HTML error message with link to admin upgrade page
*/
- public static function adminUpgradeNotice()
- {
- $link_text = __('Update settings', \JustCustomFields::TEXTDOMAIN);
- $link = ''.$link_text.' ';
+ public static function adminUpgradeNotice() {
+ $link_text = __( 'Update settings', 'jcf' );
+ $link = '' . $link_text . ' ';
- $warning = __('Thank you for upgrading Just Custom Field plugin. You need to update your settings to continue using the plugin. {link}', \JustCustomFields::TEXTDOMAIN);
- $warning = str_replace('{link}', $link, $warning);
+ $warning = __( 'Thank you for upgrading Just Custom Field plugin. You need to update your settings to continue using the plugin. {link}', 'jcf' );
+ $warning = str_replace( '{link}', $link, $warning );
printf( '', 'notice notice-error', $warning );
}
@@ -35,20 +37,19 @@ public static function adminUpgradeNotice()
*
* @return Migration[]
*/
- public function findMigrations()
- {
- $version = $this->_dL->getStorageVersion();
+ public function find_migrations() {
+ $version = $this->_dl->get_storage_version();
if ( ! $version ) {
$version = self::guessVersion();
}
$migrations = array();
- if ( $migration_files = $this->_getMigrationFiles($version) ) {
+ if ( $migration_files = $this->_getMigrationFiles( $version ) ) {
foreach ( $migration_files as $ver => $file ) {
- $class_name = '\\jcf\\migrations\\' . preg_replace('/\.php$/', '', basename($file));
+ $class_name = '\\jcf\\migrations\\' . preg_replace( '/\.php$/', '', basename( $file ) );
require_once $file;
- $migrations[$ver] = new $class_name();
+ $migrations[ $ver ] = new $class_name();
}
}
@@ -58,32 +59,31 @@ public function findMigrations()
/**
* Scan migrations directory and filter outdated migration based on current version
*
- * @param float $version
+ * @param float $version Float version.
*
* @return array
*/
- protected function _getMigrationFiles($version)
- {
+ protected function _getMigrationFiles( $version ) {
$folder = JCF_ROOT . '/migrations';
- $files = scandir($folder);
+ $files = scandir( $folder );
$migrations = array();
foreach ( $files as $key => $file ) {
- if ( $file == '.' || $file == '..' || !is_file($folder . '/' . $file)
- || ! preg_match('/^m([\dx]+)/', $file, $match)
+ if ( '.' === $file || '..' === $file || ! is_file( $folder . '/' . $file )
+ || ! preg_match( '/^m([\dx]+)/', $file, $match )
) {
continue;
}
- $mig_version = str_replace('x', '.', $match[1]);
- if ( version_compare($mig_version, $version, '<=') ) {
+ $mig_version = str_replace( 'x', '.', $match[1] );
+ if ( version_compare( $mig_version, $version, '<=' ) ) {
continue;
}
- $migrations[$mig_version] = $folder . '/' . $file;
+ $migrations[ $mig_version ] = $folder . '/' . $file;
}
- ksort($migrations);
+ ksort( $migrations );
return $migrations;
}
@@ -91,19 +91,19 @@ protected function _getMigrationFiles($version)
/**
* Do test run to check that we can migrate or need to show warnings
*
- * @param Migration[] $migrations
+ * @param Migration[] $migrations Migrations.
+ *
* @return array
*/
- public function testMigrate($migrations)
- {
- $data = null;
+ public function test_migrate( $migrations ) {
+ $data = null;
$warnings = array();
- foreach ($migrations as $ver => $m) {
- if ( $warning = $m->runTest( $data ) ) {
- $warnings[$ver] = $warning;
+ foreach ( $migrations as $ver => $m ) {
+ if ( $warning = $m->run_test( $data ) ) {
+ $warnings[ $ver ] = $warning;
}
- $data = $m->runUpdate($data);
+ $data = $m->run_update( $data );
}
return $warnings;
@@ -112,43 +112,42 @@ public function testMigrate($migrations)
/**
* Run migrations
*
- * @param Migration[] $migrations
+ * @param Migration[] $migrations Migrations.
+ *
* @return boolean
*/
- public function migrate($migrations)
- {
- if ( !empty($migrations) ) {
- set_time_limit(0);
+ public function migrate( $migrations ) {
+ if ( ! empty( $migrations ) ) {
+ set_time_limit( 0 );
$data = null;
- foreach ($migrations as $ver => $m) {
- $data = $m->runUpdate($data, Migration::MODE_UPDATE);
+ foreach ( $migrations as $ver => $m ) {
+ $data = $m->run_update( $data, Migration::MODE_UPDATE );
}
- $fields = $data[Migration::FIELDS_KEY];
- $fieldsets = $data[Migration::FIELDSETS_KEY];
+ $fields = $data[ Migration::FIELDS_KEY ];
+ $fieldsets = $data[ Migration::FIELDSETS_KEY ];
- $fields = $this->_updateFieldsVersion($fields);
+ $fields = $this->_update_fields_version( $fields );
- $this->_dL->setFields($fields);
- $this->_dL->setFieldsets($fieldsets);
- $updated = $this->_dL->saveFieldsData() && $this->_dL->saveFieldsetsData();
- }
- else {
+ $this->_dl->set_fields( $fields );
+ $this->_dl->set_fieldsets( $fieldsets );
+ $updated = $this->_dl->save_fields_data() && $this->_dl->save_fieldsets_data();
+ } else {
$migrations = array();
- $updated = true;
+ $updated = true;
}
- // do cleanup
+ // do cleanup.
if ( $updated ) {
- $this->_dL->saveStorageVersion();
- foreach ($migrations as $ver => $m) {
- $m->runCleanup();
+ $this->_dl->save_storage_version();
+ foreach ( $migrations as $ver => $m ) {
+ $m->run_cleanup();
}
+
return true;
- }
- else {
- $this->addError('Error! Upgrade failed. Please contact us through github to help you and update migration scripts.');
+ } else {
+ $this->add_error( 'Error! Upgrade failed. Please contact us through github to help you and update migration scripts.' );
}
}
@@ -159,50 +158,51 @@ public function migrate($migrations)
*
* @return boolean
*/
- public function isStorageWritable()
- {
- $data_source = Settings::getDataSourceType();
-
- // if we use filesystem we need to know it's writable
- if ( $data_source !== Settings::CONF_SOURCE_DB ) {
- $filepath = $this->_dL->getConfigFilePath();
- $filedir = dirname($filepath);
- if ( (!is_dir($filedir) && !wp_mkdir_p($filedir)) || !wp_is_writable($filedir) ) {
- $this->addError('Error! Please check that settings directory is writable "' . dirname($filepath) . '"');
- }
- elseif ( is_file($filepath) && ! wp_is_writable($filepath) ) {
- $this->addError('Error! Please check that settings file is writable "' . ($filepath) . '"');
+ public function is_storage_writable() {
+ $data_source = Settings::get_data_source_type();
+
+ // if we use filesystem we need to know it's writable.
+ if ( Settings::CONF_SOURCE_DB !== $data_source ) {
+ $filepath = $this->_dl->get_config_file_path();
+ $filedir = dirname( $filepath );
+ if ( ( ! is_dir( $filedir ) && ! wp_mkdir_p( $filedir ) ) || ! wp_is_writable( $filedir ) ) {
+ $this->add_error( 'Error! Please check that settings directory is writable "' . dirname( $filepath ) . '"' );
+ } elseif ( is_file( $filepath ) && ! wp_is_writable( $filepath ) ) {
+ $this->add_error( 'Error! Please check that settings file is writable "' . ( $filepath ) . '"' );
}
}
- return ! $this->hasErrors();
+ return ! $this->has_errors();
}
/**
* Set fields version to all fields
*
- * @param array $fields_data
+ * @param array $fields_data Fields data.
+ *
* @return array
*/
- public function _updateFieldsVersion($fields_data)
- {
+ public function _update_fields_version( $fields_data ) {
$version = \JustCustomFields::$version;
- foreach ($fields_data as $post_type => $fields) {
- if ( !is_array($fields) ) continue;
+ foreach ( $fields_data as $post_type => $fields ) {
+ if ( ! is_array( $fields ) ) {
+ continue;
+ }
- foreach ($fields as $id => $field) {
- // collection also has fields inside
- if ( !empty($field['fields']) && is_array($field['fields']) ) {
+ foreach ( $fields as $id => $field ) {
+ // collection also has fields inside.
+ if ( ! empty( $field['fields'] ) && is_array( $field['fields'] ) ) {
foreach ( $field['fields'] as $fid => $f ) {
- $fields_data[$post_type][$id]['fields'][$fid]['_version'] = $version;
+ $fields_data[ $post_type ][ $id ]['fields'][ $fid ]['_version'] = $version;
}
}
- // update field version
- $fields_data[$post_type][$id]['_version'] = $version;
+ // update field version.
+ $fields_data[ $post_type ][ $id ]['_version'] = $version;
}
}
+
return $fields_data;
}
@@ -212,24 +212,27 @@ public function _updateFieldsVersion($fields_data)
*
* @return bool|int|mixed
*/
- public static function guessVersion()
- {
- // check data source key exists. in v2.3 it was different key
- if ( ! $data_source = Settings::getDataSourceType( '' ) ) {
- $data_source = get_site_option('jcf_read_settings', Settings::CONF_SOURCE_DB);
- update_site_option(Settings::OPT_SOURCE, $data_source);
+ public static function guessVersion() {
+ // check data source key exists. in v2.3 it was different key.
+ if ( ! $data_source = Settings::get_data_source_type( '' ) ) {
+ $data_source = get_site_option( 'jcf_read_settings', Settings::CONF_SOURCE_DB );
+ update_site_option( Settings::OPT_SOURCE, $data_source );
}
- $fields = self::guessFields();
+ $fields = self::guess_fields();
- // we can't guess version if can't find any settings
- if ( empty($fields) ) return false;
+ // we can't guess version if can't find any settings.
+ if ( empty( $fields ) ) {
+ return false;
+ }
$latest_version = 0;
- foreach ($fields as $post_type => $post_type_fields) {
- foreach ($post_type_fields as $field) {
- if (empty($field['_version'])) continue;
- $latest_version = max($latest_version, $field['_version']);
+ foreach ( $fields as $post_type => $post_type_fields ) {
+ foreach ( $post_type_fields as $field ) {
+ if ( empty( $field['_version'] ) ) {
+ continue;
+ }
+ $latest_version = max( $latest_version, $field['_version'] );
}
}
@@ -243,77 +246,77 @@ public static function guessVersion()
*
* @return array|bool
*/
- public static function guessFields()
- {
- // try to get fields from current data layer. maybe we don't have much changes
+ public static function guess_fields() {
+ // try to get fields from current data layer. maybe we don't have much changes.
$data_layer = DataLayerFactory::create();
- if ( $fields = $data_layer->getFields() ) {
+ if ( $fields = $data_layer->get_fields() ) {
return $fields;
}
- // we can't find the fields now we should try to search them manually
- $data_source = Settings::getDataSourceType();
- $network_mode = Settings::getNetworkMode();
- $post_types = jcf_get_post_types();
+ // we can't find the fields now we should try to search them manually.
+ $data_source = Settings::get_data_source_type();
+ $network_mode = Settings::get_network_mode();
+ $post_types = jcf_get_post_types();
- // check old options from DB
- if ( Settings::CONF_SOURCE_DB == $data_source ) {
+ // check old options from DB.
+ if ( Settings::CONF_SOURCE_DB === $data_source ) {
$getter = 'get_option';
- if ( Settings::CONF_MS_NETWORK == $network_mode ) {
+ if ( Settings::CONF_MS_NETWORK === $network_mode ) {
$getter = 'get_site_option';
}
- // ver < 3.1 has key 'jcf-fields'
- if ( $fields = $getter('jcf-fields') ) {
+ // ver < 3.1 has key 'jcf-fields'.
+ if ( $fields = $getter( 'jcf-fields' ) ) {
return $fields;
}
- // ver < 3.0 has keys based on post types: 'jcf_fields-{$post_type}'
+ // ver < 3.0 has keys based on post types: 'jcf_fields-{$post_type}'.
$grouped_fields = array();
foreach ( $post_types as $pt => $post_type ) {
- $grouped_fields[$pt] = array();
- if ( $fields = $getter("jcf_fields-{$pt}") ) {
- $grouped_fields[$pt] = $fields;
+ $grouped_fields[ $pt ] = array();
+ if ( $fields = $getter( "jcf_fields-{$pt}" ) ) {
+ $grouped_fields[ $pt ] = $fields;
}
}
+
return $grouped_fields;
}
- // check old options from file system settings
- if ( Settings::CONF_SOURCE_FS_THEME == $data_source || Settings::CONF_SOURCE_FS_GLOBAL == $data_source ) {
+ // check old options from file system settings.
+ if ( Settings::CONF_SOURCE_FS_THEME === $data_source || Settings::CONF_SOURCE_FS_GLOBAL === $data_source ) {
$base_folder = get_stylesheet_directory();
- if ( Settings::CONF_SOURCE_FS_GLOBAL == $data_source ) {
+ if ( Settings::CONF_SOURCE_FS_GLOBAL === $data_source ) {
$base_folder = WP_CONTENT_DIR;
}
$file_pathes = array(
- 'jcf/config.json', // starting from v3.1
- 'jcf-settings/jcf_settings.json', // before v3.1
+ 'jcf/config.json', // starting from v3.1.
+ 'jcf-settings/jcf_settings.json', // before v3.1.
);
foreach ( $file_pathes as $file ) {
- if ( ! is_file("$base_folder/$file") ) {
+ if ( ! is_file( "$base_folder/$file" ) ) {
continue;
}
- $settings = file_get_contents("$base_folder/$file");
- if (empty($settings) || ! $settings = json_decode($settings, true)) {
+ $settings = file_get_contents( "$base_folder/$file" );
+ if ( empty( $settings ) || ! $settings = json_decode( $settings, true ) ) {
continue;
}
- $settings = (array)$settings;
+ $settings = (array) $settings;
- // ver >= 3.0 has key 'fields'
- if ( !empty($settings['fields']) ) {
+ // ver >= 3.0 has key 'fields'.
+ if ( ! empty( $settings['fields'] ) ) {
return $settings['fields'];
}
- // ver < 3.0 has key 'field_settings'
- if ( !empty($settings['field_settings']) ) {
+ // ver < 3.0 has key 'field_settings'.
+ if ( ! empty( $settings['field_settings'] ) ) {
return $settings['field_settings'];
}
}
}
- // we didn't find any fields
+ // we didn't find any fields.
return false;
}
}
\ No newline at end of file
diff --git a/models/Settings.php b/models/Settings.php
index 3c514b6..9450c24 100755
--- a/models/Settings.php
+++ b/models/Settings.php
@@ -4,8 +4,10 @@
use jcf\core;
-class Settings extends core\Model
-{
+/**
+ * Class Settings
+ */
+class Settings extends core\Model {
const CONF_MS_NETWORK = 'network';
const CONF_MS_SITE = 'site';
const CONF_SOURCE_DB = 'database';
@@ -16,35 +18,59 @@ class Settings extends core\Model
const OPT_MULTISITE = 'jcf_multisite_setting';
const OPT_GOOGLEMAPS = 'jcf_googlemaps_apikey';
+ /**
+ * Site domain
+ *
+ * @var $site_domain
+ */
private static $site_domain;
+ /**
+ * Source
+ *
+ * @var $source
+ */
public $source;
+
+ /**
+ * Network
+ *
+ * @var $network
+ */
public $network;
+
+ /**
+ * Googlemaps API key
+ *
+ * @var $googlemaps_api_key
+ */
public $googlemaps_api_key;
/**
* Get source settings
*
- * @param string $default
+ * @param string $default Default.
+ *
* @return string
*/
- public static function getDataSourceType( $default = null )
- {
- if ( is_null($default) ) {
+ public static function get_data_source_type( $default = null ) {
+ if ( is_null( $default ) ) {
$default = self::CONF_SOURCE_DB;
}
- return get_site_option(self::OPT_SOURCE, $default);
+
+ return get_site_option( self::OPT_SOURCE, $default );
}
/**
* Get network settings
+ *
* @return string
*/
- public static function getNetworkMode()
- {
- if ( MULTISITE && $network = get_site_option(self::OPT_MULTISITE) ) {
+ public static function get_network_mode() {
+ if ( MULTISITE && $network = get_site_option( self::OPT_MULTISITE ) ) {
return $network;
}
+
return self::CONF_MS_SITE;
}
@@ -53,38 +79,38 @@ public static function getNetworkMode()
*
* @return string
*/
- public static function getGoogleMapsApiKey()
- {
- $domain = self::getSiteDomain();
- $googlemaps_settings = get_option(self::OPT_GOOGLEMAPS, array());
- if ( !empty($googlemaps_settings[$domain]) ) {
- return $googlemaps_settings[$domain];
+ public static function get_google_maps_api_key() {
+ $domain = self::get_site_domain();
+ $googlemaps_settings = get_option( self::OPT_GOOGLEMAPS, array() );
+ if ( ! empty( $googlemaps_settings[ $domain ] ) ) {
+ return $googlemaps_settings[ $domain ];
}
+
return '';
}
/**
* Save settings
- * @return boolean
*/
- public function save()
- {
- $this->_updateNetworkMode();
- $this->_updateDataSource();
- $this->_updateGoogleMapsApiKey();
+ public function save() {
+ $this->_update_network_mode();
+ $this->_update_data_source();
+ $this->_update_google_maps_api_key();
}
/**
* Update source data
+ *
* @return boolean
*/
- protected function _updateDataSource()
- {
- if ( !$this->validateDataSource() )
+ protected function _update_data_source() {
+ if ( ! $this->validate_data_source() ) {
return false;
+ }
+
+ if ( update_site_option( self::OPT_SOURCE, $this->source ) ) {
+ $this->add_message( 'source_updated' );
- if ( update_site_option(self::OPT_SOURCE, $this->source) ) {
- $this->addMessage('source_updated');
return true;
}
@@ -93,15 +119,17 @@ protected function _updateDataSource()
/**
* Update network data
+ *
* @return boolean
*/
- protected function _updateNetworkMode()
- {
- if ( !$this->validateNetworkMode() )
+ protected function _update_network_mode() {
+ if ( ! $this->validate_network_mode() ) {
return false;
+ }
+
+ if ( update_site_option( self::OPT_MULTISITE, $this->network ) ) {
+ $this->add_message( 'ms_updated' );
- if ( update_site_option(self::OPT_MULTISITE, $this->network) ) {
- $this->addMessage('ms_updated');
return true;
}
@@ -113,12 +141,12 @@ protected function _updateNetworkMode()
*
* @return boolean
*/
- protected function _updateGoogleMapsApiKey()
- {
- $domain = self::getSiteDomain();
- $googlemaps_settings = get_option(self::OPT_GOOGLEMAPS, array());
- $googlemaps_settings[$domain] = $this->googlemaps_api_key;
- return update_option(self::OPT_GOOGLEMAPS, $googlemaps_settings);
+ protected function _update_google_maps_api_key() {
+ $domain = self::get_site_domain();
+ $googlemaps_settings = get_option( self::OPT_GOOGLEMAPS, array() );
+ $googlemaps_settings[ $domain ] = $this->googlemaps_api_key;
+
+ return update_option( self::OPT_GOOGLEMAPS, $googlemaps_settings );
}
/**
@@ -126,78 +154,77 @@ protected function _updateGoogleMapsApiKey()
*
* @return mixed
*/
- protected static function getSiteDomain()
- {
+ protected static function get_site_domain() {
if ( empty( self::$site_domain ) ) {
- $site_url = get_site_url();
- self::$site_domain = parse_url($site_url, PHP_URL_HOST);
+ $site_url = get_site_url();
+ self::$site_domain = parse_url( $site_url, PHP_URL_HOST );
}
return self::$site_domain;
}
/**
- * error messages
+ * Error messages
*
* @return array
*/
- public function messageTemplates()
- {
+ public function message_templates() {
return array(
- 'empty_source' => __('Settings storage update FAILED! . Choose an option for the data storage', \JustCustomFields::TEXTDOMAIN),
- 'fs_theme_not_writable' => __('Settings storage update FAILED! . Check writable permissions of directory ' . get_stylesheet_directory() . '/jcf-settings/', \JustCustomFields::TEXTDOMAIN),
- 'fs_global_not_writable' => __('Settings storage update FAILED! . Check writable permissions of directory ' . get_home_path() . 'wp-content/jcf-settings/', \JustCustomFields::TEXTDOMAIN),
+ 'empty_source' => __( 'Settings storage update FAILED! . Choose an option for the data storage', 'jcf' ),
+ 'fs_theme_not_writable' => __( 'Settings storage update FAILED! . Check writable permissions of directory ' . get_stylesheet_directory() . '/jcf-settings/', 'jcf' ),
+ 'fs_global_not_writable' => __( 'Settings storage update FAILED! . Check writable permissions of directory ' . get_home_path() . 'wp-content/jcf-settings/', 'jcf' ),
- 'empty_ms' => __('MultiSite settings update FAILED! Choose an option for the multisite.', \JustCustomFields::TEXTDOMAIN),
+ 'empty_ms' => __( 'MultiSite settings update FAILED! Choose an option for the multisite.', 'jcf' ),
- 'source_updated' => __('Settings storage configurations has been updated.', \JustCustomFields::TEXTDOMAIN),
- 'ms_updated' => __('MultiSite settings has been updated.', \JustCustomFields::TEXTDOMAIN),
+ 'source_updated' => __( 'Settings storage configurations has been updated.', 'jcf' ),
+ 'ms_updated' => __( 'MultiSite settings has been updated.', 'jcf' ),
);
}
/**
* Validate current value of source attribute
+ *
* @return bool
*/
- public function validateDataSource()
- {
- if ( empty($this->source) ) {
- $this->addError('empty_source');
+ public function validate_data_source() {
+ if ( empty( $this->source ) ) {
+ $this->add_error( 'empty_source' );
}
- if ( $this->source == self::CONF_SOURCE_FS_THEME ) {
- $path = apply_filters('jcf_config_filepath', get_stylesheet_directory() . '/jcf/config.json', self::CONF_SOURCE_FS_THEME);
- $fs_theme_storage = dirname($path);
- if ( !wp_mkdir_p($fs_theme_storage) || !is_writable($fs_theme_storage) ) {
- $this->addError( 'fs_theme_not_writable' );
+ if ( self::CONF_SOURCE_FS_THEME === $this->source ) {
+ $path = apply_filters( 'jcf_config_filepath', get_stylesheet_directory() . '/jcf/config.json', self::CONF_SOURCE_FS_THEME );
+ $fs_theme_storage = dirname( $path );
+ if ( ! wp_mkdir_p( $fs_theme_storage ) || ! is_writable( $fs_theme_storage ) ) {
+ $this->add_error( 'fs_theme_not_writable' );
}
}
- if ( $this->source == self::CONF_SOURCE_FS_GLOBAL ) {
- $path = apply_filters('jcf_config_filepath', WP_CONTENT_DIR . '/jcf/config.json', self::CONF_SOURCE_FS_GLOBAL);
- $fs_global_storage = dirname($path);
- if ( !wp_mkdir_p($fs_global_storage) || !is_writable($fs_global_storage) ) {
- $this->addError('fs_global_not_writable');
+ if ( self::CONF_SOURCE_FS_GLOBAL === $this->source ) {
+ $path = apply_filters( 'jcf_config_filepath', WP_CONTENT_DIR . '/jcf/config.json', self::CONF_SOURCE_FS_GLOBAL );
+ $fs_global_storage = dirname( $path );
+ if ( ! wp_mkdir_p( $fs_global_storage ) || ! is_writable( $fs_global_storage ) ) {
+ $this->add_error( 'fs_global_not_writable' );
}
}
- return ! $this->hasErrors();
+ return ! $this->has_errors();
}
/**
- * validate current value of network mode attribute
+ * Validate current value of network mode attribute
+ *
* @return bool
*/
- public function validateNetworkMode()
- {
- if ( !MULTISITE )
+ public function validate_network_mode() {
+ if ( ! MULTISITE ) {
return false;
+ }
- if ( empty($this->network) ) {
+ if ( empty( $this->network ) ) {
$this->network = self::CONF_MS_SITE;
}
- return ! $this->hasErrors();
+ return ! $this->has_errors();
}
}
diff --git a/models/Shortcodes.php b/models/Shortcodes.php
index d0a54a7..cf463d1 100755
--- a/models/Shortcodes.php
+++ b/models/Shortcodes.php
@@ -4,67 +4,73 @@
use jcf\core;
-class Shortcodes extends core\Model
-{
+/**
+ * Class Shortcodes
+ */
+class Shortcodes extends core\Model {
/**
- * Do shortcode
- * @param array $args Attributes from shortcode
- * @return string Field content
+ * Do shortcode
+ *
+ * @param array $args Attributes from shortcode.
+ *
+ * @return string Field content
*/
- protected function _initShortcode( $args )
- {
- extract(shortcode_atts(array(
- 'field' => '',
+ protected function _initShortcode( $args ) {
+ extract( shortcode_atts( array(
+ 'field' => '',
'post_id' => '',
- ), $args));
+ ), $args ) );
- //get post id
- $post_id = !empty($args['post_id']) ? $args['post_id'] : get_the_ID();
- //get post type
- $post_type = get_post_type($post_id);
- //get field settings
- $field_settings = $this->_dL->getFields();
- if ( empty($field_settings[$post_type]) )
+ // get post id.
+ $post_id = ! empty( $args['post_id'] ) ? $args['post_id'] : get_the_ID();
+ // get post type.
+ $post_type = get_post_type( $post_id );
+ // get field settings.
+ $field_settings = $this->_dl->get_fields();
+ if ( empty( $field_settings[ $post_type ] ) ) {
return false;
+ }
- //get field id
- foreach ( $field_settings[$post_type] as $key_field => $field ) {
- if ( strcmp($args['field'], $field['slug']) === 0 ) {
+ // get field id.
+ foreach ( $field_settings[ $post_type ] as $key_field => $field ) {
+ if ( strcmp( $args['field'], $field['slug'] ) === 0 ) {
$field_id = $key_field;
break;
}
}
- // init field object and do shortcode
- if ( !empty($field_id) ) {
- $field_model = new Field();
+ // init field object and do shortcode.
+ if ( ! empty( $field_id ) ) {
+ $field_model = new Field();
$field_model->post_type = $post_type;
- $field_model->field_id = $field_id;
- $field_obj = core\JustFieldFactory::create($field_model);
- if ( !$field_obj ) return false;
+ $field_model->field_id = $field_id;
+ $field_obj = core\JustFieldFactory::create( $field_model );
+ if ( ! $field_obj ) {
+ return false;
+ }
- $field_obj->setPostID($post_id);
+ $field_obj->set_post_id( $post_id );
- unset($args['field']);
- return $field_obj->doShortcode($args);
- }
- else {
+ unset( $args['field'] );
+
+ return $field_obj->do_shortcode( $args );
+ } else {
return false;
}
}
/**
- * Shortcode [jcf-value]
- * @param array $args Attributes from shortcode
- * @return string Field content
+ * Shortcode [jcf-value]
+ *
+ * @param array $args Attributes from shortcode.
+ *
+ * @return string Field content
*/
- public function getFieldValue( $args )
- {
- if ( !empty($args['field']) ) {
- return $this->_initShortcode($args);
- }
- else {
- return _e('Error! "field" parameter is missing', \JustCustomFields::TEXTDOMAIN);
+ public function get_field_value( $args ) {
+ if ( ! empty( $args['field'] ) ) {
+ return $this->_initShortcode( $args );
+ } else {
+ return esc_html_e( 'Error! "field" parameter is missing', 'jcf' );
}
}
diff --git a/views/_footer.php b/views/_footer.php
index 0f33118..32d6ba1 100644
--- a/views/_footer.php
+++ b/views/_footer.php
@@ -1,3 +1,2 @@
-
-
+
\ No newline at end of file
diff --git a/views/_header.php b/views/_header.php
index 6a12ab9..126f214 100644
--- a/views/_header.php
+++ b/views/_header.php
@@ -1,8 +1,6 @@
-
+
-
-
-
-
+
+
diff --git a/views/_notices.php b/views/_notices.php
index 4f5e4bd..ddb7a2c 100644
--- a/views/_notices.php
+++ b/views/_notices.php
@@ -1,17 +1,24 @@
-_messages) ) :?>
- _messages as $message ):?>
-
-
-
' . __('Dismiss this notice.', \JustCustomFields::TEXTDOMAIN) . ' ') ?>
+_messages ) ) : ?>
+ _messages as $message ) : ?>
+
+
+
' . esc_html__( 'Dismiss this notice.', 'jcf' ) . ' ' ) ?>
-_errors) ) :?>
- _errors as $error ):?>
-
-
-
' . __('Dismiss this notice.', \JustCustomFields::TEXTDOMAIN) . ' '); ?>
+_errors ) ) : ?>
+ _errors as $error ) : ?>
+
+
+
' . esc_html__( 'Dismiss this notice.', 'jcf' ) . ' ' ); ?>
\ No newline at end of file
diff --git a/views/_tabs.php b/views/_tabs.php
index e295b20..fa72e5a 100644
--- a/views/_tabs.php
+++ b/views/_tabs.php
@@ -1,6 +1,15 @@
+
+
-
-
-
+
+
+
diff --git a/views/admin/index.php b/views/admin/index.php
index 13bc280..695418a 100644
--- a/views/admin/index.php
+++ b/views/admin/index.php
@@ -1,21 +1,31 @@
-
+
-
+
-
+
Post Types
-
+
Taxonomies
-
+
diff --git a/views/fields/collection.php b/views/fields/collection.php
index e4e36f8..659a27c 100644
--- a/views/fields/collection.php
+++ b/views/fields/collection.php
@@ -1,55 +1,72 @@
-
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
- $field) : ?>
-
-
-
-
-
-
-
+
+
+
+
+ $field ) : ?>
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/views/fields/form.php b/views/fields/form.php
index d09eb72..f65856c 100644
--- a/views/fields/form.php
+++ b/views/fields/form.php
@@ -1,63 +1,78 @@
-idBase == $field->id) ? __('Add', \JustCustomFields::TEXTDOMAIN) : __('Edit', \JustCustomFields::TEXTDOMAIN); ?>
+id_base === $field->id ) ? __( 'Add', 'jcf' ) : __( 'Edit', 'jcf' ); ?>