Added dependency plugins

This commit is contained in:
Moris Zen
2018-06-25 00:00:37 +02:00
parent 720a1c31a4
commit f069f6782f
698 changed files with 289637 additions and 1 deletions

View File

@@ -0,0 +1,615 @@
<?php
/*
* acf_esc_html
*
* This function will encode <script> tags for safe output
*
* @type function
* @date 25/6/17
* @since 5.6.0
*
* @param string (string)
* @return (string)
*/
function acf_esc_html( $string = '' ) {
// cast
$string = (string) $string;
// replace
$string = str_replace('<script', htmlspecialchars('<script'), $string);
$string = str_replace('</script', htmlspecialchars('</script'), $string);
// return
return $string;
}
/**
* acf_clean_atts
*
* This function will remove empty attributes
*
* @date 3/10/17
* @since 5.6.3
*
* @param array $atts
* @return array
*/
function acf_clean_atts( $atts = array() ) {
// loop
foreach( $atts as $k => $v ) {
if( $v === '' ) unset( $atts[ $k ] );
}
// return
return $atts;
}
/**
* acf_get_atts
*
* This function will return an array of HTML attributes
*
* @date 2/10/17
* @since 5.6.3
*
* @param n/a
* @return n/a
*/
/*
function acf_get_atts( $array, $keys ) {
// vars
$atts = array();
// append attributes
foreach( $keys as $k ) {
if( isset($array[ $k ]) ) $atts[ $k ] = $array[ $k ];
}
// modify special attributes
foreach( array('readonly', 'disabled', 'required') as $k ) {
$atts[ $k ] = $atts[ $k ] ? $k : '';
}
// clean up blank attributes
foreach( $atts as $k => $v ) {
if( $v === '' ) unset( $atts[ $k ] );
}
// return
return $atts;
}
*/
/*
* acf_esc_atts
*
* This function will escape an array of attributes and return as HTML
*
* @type function
* @date 27/6/17
* @since 5.6.0
*
* @param $atts (array)
* @return (string)
*/
function acf_esc_atts( $atts = array() ) {
// vars
$html = '';
// loop
foreach( $atts as $k => $v ) {
// string
if( is_string($v) ) {
// don't trim value
if( $k !== 'value') $v = trim($v);
// boolean
} elseif( is_bool($v) ) {
$v = $v ? 1 : 0;
// object
} elseif( is_array($v) || is_object($v) ) {
$v = json_encode($v);
}
// append
$html .= esc_attr( $k ) . '="' . esc_attr( $v ) . '" ';
}
// return
return trim( $html );
}
/*
* acf_esc_atts_e
*
* This function will echo acf_esc_atts
*
* @type function
* @date 27/6/17
* @since 5.6.0
*
* @param $atts (array)
* @return n/a
*/
function acf_esc_atts_e( $atts = array() ) {
echo acf_esc_atts( $atts );
}
/*
* acf_get_text_input
*
* This function will return HTML for a text input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return (string)
*/
function acf_get_text_input( $atts = array() ) {
$atts['type'] = isset($atts['type']) ? $atts['type'] : 'text';
return '<input ' . acf_esc_atts( $atts ) . ' />';
}
/*
* acf_text_input
*
* This function will output HTML for a text input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return n/a
*/
function acf_text_input( $atts = array() ) {
echo acf_get_text_input( $atts );
}
/*
* acf_get_hidden_input
*
* This function will return HTML for a hidden input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return (string)
*/
function acf_get_hidden_input( $atts = array() ) {
$atts['type'] = 'hidden';
return acf_get_text_input( $atts );
}
/*
* acf_hidden_input
*
* This function will output HTML for a generic input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return n/a
*/
function acf_hidden_input( $atts = array() ) {
echo acf_get_hidden_input( $atts ) . "\n";
}
/*
* acf_get_textarea_input
*
* This function will return HTML for a textarea input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return (string)
*/
function acf_get_textarea_input( $atts = array() ) {
$value = acf_extract_var( $atts, 'value', '' );
return '<textarea ' . acf_esc_atts( $atts ) . '>' . esc_textarea( $value ) . '</textarea>';
}
/*
* acf_textarea_input
*
* This function will output HTML for a textarea input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return n/a
*/
function acf_textarea_input( $atts = array() ) {
echo acf_get_textarea_input( $atts );
}
/*
* acf_get_checkbox_input
*
* This function will return HTML for a checkbox input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return (string)
*/
function acf_get_checkbox_input( $atts = array() ) {
$label = acf_extract_var( $atts, 'label', '' );
$checked = acf_maybe_get( $atts, 'checked', '' );
$atts['type'] = acf_maybe_get( $atts, 'type', 'checkbox' );
return '<label' . ($checked ? ' class="selected"' : '') . '><input ' . acf_esc_attr( $atts ) . '/>' . acf_esc_html( $label ) . '</label>';
}
/*
* acf_checkbox_input
*
* This function will output HTML for a checkbox input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return n/a
*/
function acf_checkbox_input( $atts = array() ) {
echo acf_get_checkbox_input( $atts );
}
/*
* acf_get_radio_input
*
* This function will return HTML for a radio input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return (string)
*/
function acf_get_radio_input( $atts = array() ) {
$atts['type'] = 'radio';
return acf_get_checkbox_input( $atts );
}
/*
* acf_radio_input
*
* This function will output HTML for a radio input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return n/a
*/
function acf_radio_input( $atts = array() ) {
echo acf_get_radio_input( $atts );
}
/*
* acf_get_select_input
*
* This function will return HTML for a select input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return (string)
*/
function acf_get_select_input( $atts = array() ) {
// vars
$value = (array) acf_extract_var( $atts, 'value' );
$choices = (array) acf_extract_var( $atts, 'choices' );
// html
$html = '';
$html .= '<select ' . acf_esc_atts( $atts ) . '>' . "\n";
$html .= acf_walk_select_input( $choices, $value );
$html .= '</select>' . "\n";
// return
return $html;
}
/*
* acf_walk_select_input
*
* This function will return the HTML for a select input's choices
*
* @type function
* @date 27/6/17
* @since 5.6.0
*
* @param $post_id (int)
* @return $post_id (int)
*/
function acf_walk_select_input( $choices = array(), $values = array(), $depth = 0 ) {
// bail ealry if no choices
if( empty($choices) ) return '';
// vars
$html = '';
// sanitize values for 'selected' matching
if( $depth == 0 ) {
$values = array_map('esc_attr', $values);
}
// loop
foreach( $choices as $value => $label ) {
// optgroup
if( is_array($label) ){
$html .= '<optgroup label="' . esc_attr($value) . '">' . "\n";
$html .= acf_walk_select_input( $label, $values, $depth+1 );
$html .= '</optgroup>';
// option
} else {
// vars
$atts = array( 'value' => $value );
$pos = array_search( esc_attr($value), $values );
// selected
if( $pos !== false ) {
$atts['selected'] = 'selected';
$atts['data-i'] = $pos;
}
// append
$html .= '<option ' . acf_esc_attr($atts) . '>' . esc_html($label) . '</option>' . "\n";
}
}
// return
return $html;
}
/*
* acf_select_input
*
* This function will output HTML for a select input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return n/a
*/
function acf_select_input( $atts = array() ) {
echo acf_get_select_input( $atts );
}
/*
function acf_test_esc_html( $string = '' ) {
$s = '';
$time_start = microtime(true);
$s .= wp_kses_post( $string );
$s .= ' = ('. (microtime(true) - $time_start) .')';
$s .= '-----';
$time_start = microtime(true);
$s .= str_replace(array('<script', '</script'), array(htmlspecialchars('<script'), htmlspecialchars('</script')), $string);
$s .= ' = ('. (microtime(true) - $time_start) .')';
$time_start = microtime(true);
if( strpos($string, '<script') ) {
$s .= str_replace(array('<script', '</script'), array(htmlspecialchars('<script'), htmlspecialchars('</script')), $string);
}
$s .= ' = ('. (microtime(true) - $time_start) .')';
return $s;
}
*/
/*
* acf_get_file_input
*
* This function will return HTML for a file input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return (string)
*/
function acf_get_file_input( $atts = array() ) {
$atts['type'] = 'file';
return acf_get_text_input( $atts );
}
/*
* acf_file_input
*
* This function will output HTML for a file input
*
* @type function
* @date 3/02/2014
* @since 5.0.0
*
* @param $atts
* @return n/a
*/
function acf_file_input( $atts = array() ) {
echo acf_get_file_input( $atts );
}
/*
* acf_esc_attr
*
* Deprecated since 5.6.0
*
* @type function
* @date 1/10/13
* @since 5.0.0
*
* @param $atts (array)
* @return n/a
*/
function acf_esc_attr( $atts ) {
return acf_esc_atts( $atts );
}
/*
* acf_esc_attr_e
*
* Deprecated since 5.6.0
*
* @type function
* @date 1/10/13
* @since 5.0.0
*
* @param $atts (array)
* @return n/a
*/
function acf_esc_attr_e( $atts ) {
acf_esc_atts_e( $atts );
}
?>

View File

@@ -0,0 +1,524 @@
<?php
/*
* acf_get_metadata
*
* This function will get a value from the DB
*
* @type function
* @date 16/10/2015
* @since 5.2.3
*
* @param $post_id (mixed)
* @param $name (string)
* @param $hidden (boolean)
* @return $return (mixed)
*/
function acf_get_metadata( $post_id = 0, $name = '', $hidden = false ) {
// vars
$value = null;
$prefix = $hidden ? '_' : '';
// get post_id info
$info = acf_get_post_id_info($post_id);
// bail early if no $post_id (acf_form - new_post)
if( !$info['id'] ) return $value;
// option
if( $info['type'] === 'option' ) {
$name = $prefix . $post_id . '_' . $name;
$value = get_option( $name, null );
// meta
} else {
$name = $prefix . $name;
$meta = get_metadata( $info['type'], $info['id'], $name, false );
if( isset($meta[0]) ) {
$value = $meta[0];
}
}
// return
return $value;
}
/*
* acf_update_metadata
*
* This function will update a value from the DB
*
* @type function
* @date 16/10/2015
* @since 5.2.3
*
* @param $post_id (mixed)
* @param $name (string)
* @param $value (mixed)
* @param $hidden (boolean)
* @return $return (boolean)
*/
function acf_update_metadata( $post_id = 0, $name = '', $value = '', $hidden = false ) {
// vars
$return = false;
$prefix = $hidden ? '_' : '';
// get post_id info
$info = acf_get_post_id_info($post_id);
// bail early if no $post_id (acf_form - new_post)
if( !$info['id'] ) return $return;
// option
if( $info['type'] === 'option' ) {
$name = $prefix . $post_id . '_' . $name;
$return = acf_update_option( $name, $value );
// meta
} else {
$name = $prefix . $name;
$return = update_metadata( $info['type'], $info['id'], $name, $value );
}
// return
return $return;
}
/*
* acf_delete_metadata
*
* This function will delete a value from the DB
*
* @type function
* @date 16/10/2015
* @since 5.2.3
*
* @param $post_id (mixed)
* @param $name (string)
* @param $hidden (boolean)
* @return $return (boolean)
*/
function acf_delete_metadata( $post_id = 0, $name = '', $hidden = false ) {
// vars
$return = false;
$prefix = $hidden ? '_' : '';
// get post_id info
$info = acf_get_post_id_info($post_id);
// bail early if no $post_id (acf_form - new_post)
if( !$info['id'] ) return $return;
// option
if( $info['type'] === 'option' ) {
$name = $prefix . $post_id . '_' . $name;
$return = delete_option( $name );
// meta
} else {
$name = $prefix . $name;
$return = delete_metadata( $info['type'], $info['id'], $name );
}
// return
return $return;
}
/*
* acf_update_option
*
* This function is a wrapper for the WP update_option but provides logic for a 'no' autoload
*
* @type function
* @date 4/01/2014
* @since 5.0.0
*
* @param $option (string)
* @param $value (mixed)
* @param autoload (mixed)
* @return (boolean)
*/
function acf_update_option( $option = '', $value = '', $autoload = null ) {
// vars
$deprecated = '';
$return = false;
// autoload
if( $autoload === null ){
$autoload = acf_get_setting('autoload') ? 'yes' : 'no';
}
// for some reason, update_option does not use stripslashes_deep.
// update_metadata -> https://core.trac.wordpress.org/browser/tags/3.4.2/wp-includes/meta.php#L82: line 101 (does use stripslashes_deep)
// update_option -> https://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/option.php#L0: line 215 (does not use stripslashes_deep)
$value = stripslashes_deep($value);
// add or update
if( get_option($option) !== false ) {
$return = update_option( $option, $value );
} else {
$return = add_option( $option, $value, $deprecated, $autoload );
}
// return
return $return;
}
/*
* acf_get_value
*
* This function will load in a field's value
*
* @type function
* @date 28/09/13
* @since 5.0.0
*
* @param $post_id (int)
* @param $field (array)
* @return (mixed)
*/
function acf_get_value( $post_id = 0, $field ) {
// allow filter to short-circuit load_value logic
//$value = apply_filters( "acf/pre_load_value", null, $post_id, $field );
//if( $value !== null ) {
// return $value;
//}
// vars
$cache_key = "get_value/post_id={$post_id}/name={$field['name']}";
// return early if cache is found
if( acf_isset_cache($cache_key) ) {
return acf_get_cache($cache_key);
}
// load value
$value = acf_get_metadata( $post_id, $field['name'] );
// if value was duplicated, it may now be a serialized string!
$value = maybe_unserialize( $value );
// no value? try default_value
if( $value === null && isset($field['default_value']) ) {
$value = $field['default_value'];
}
// filter for 3rd party customization
$value = apply_filters( "acf/load_value", $value, $post_id, $field );
$value = apply_filters( "acf/load_value/type={$field['type']}", $value, $post_id, $field );
$value = apply_filters( "acf/load_value/name={$field['_name']}", $value, $post_id, $field );
$value = apply_filters( "acf/load_value/key={$field['key']}", $value, $post_id, $field );
// update cache
acf_set_cache($cache_key, $value);
// return
return $value;
}
/*
* acf_format_value
*
* This function will format the value for front end use
*
* @type function
* @date 3/07/2014
* @since 5.0.0
*
* @param $value (mixed)
* @param $post_id (mixed)
* @param $field (array)
* @return $value
*/
function acf_format_value( $value, $post_id, $field ) {
// vars
$cache_key = "format_value/post_id={$post_id}/name={$field['name']}";
// return early if cache is found
if( acf_isset_cache($cache_key) ) {
return acf_get_cache($cache_key);
}
// apply filters
$value = apply_filters( "acf/format_value", $value, $post_id, $field );
$value = apply_filters( "acf/format_value/type={$field['type']}", $value, $post_id, $field );
$value = apply_filters( "acf/format_value/name={$field['_name']}", $value, $post_id, $field );
$value = apply_filters( "acf/format_value/key={$field['key']}", $value, $post_id, $field );
// update cache
acf_set_cache($cache_key, $value);
// return
return $value;
}
/*
* acf_update_value
*
* updates a value into the db
*
* @type action
* @date 23/01/13
*
* @param $value (mixed)
* @param $post_id (mixed)
* @param $field (array)
* @return (boolean)
*/
function acf_update_value( $value = null, $post_id = 0, $field ) {
// strip slashes
if( acf_get_setting('stripslashes') ) {
$value = stripslashes_deep($value);
}
// filter for 3rd party customization
$value = apply_filters( "acf/update_value", $value, $post_id, $field );
$value = apply_filters( "acf/update_value/type={$field['type']}", $value, $post_id, $field );
$value = apply_filters( "acf/update_value/name={$field['_name']}", $value, $post_id, $field );
$value = apply_filters( "acf/update_value/key={$field['key']}", $value, $post_id, $field );
// allow null to delete
if( $value === null ) {
return acf_delete_value( $post_id, $field );
}
// update value
$return = acf_update_metadata( $post_id, $field['name'], $value );
// update reference
acf_update_metadata( $post_id, $field['name'], $field['key'], true );
// clear cache
acf_delete_cache("get_value/post_id={$post_id}/name={$field['name']}");
acf_delete_cache("format_value/post_id={$post_id}/name={$field['name']}");
// return
return $return;
}
/*
* acf_delete_value
*
* This function will delete a value from the database
*
* @type function
* @date 28/09/13
* @since 5.0.0
*
* @param $post_id (mixed)
* @param $field (array)
* @return (boolean)
*/
function acf_delete_value( $post_id = 0, $field ) {
// action for 3rd party customization
do_action("acf/delete_value", $post_id, $field['name'], $field);
do_action("acf/delete_value/type={$field['type']}", $post_id, $field['name'], $field);
do_action("acf/delete_value/name={$field['_name']}", $post_id, $field['name'], $field);
do_action("acf/delete_value/key={$field['key']}", $post_id, $field['name'], $field);
// delete value
$return = acf_delete_metadata( $post_id, $field['name'] );
// delete reference
acf_delete_metadata( $post_id, $field['name'], true );
// clear cache
acf_delete_cache("get_value/post_id={$post_id}/name={$field['name']}");
acf_delete_cache("format_value/post_id={$post_id}/name={$field['name']}");
// return
return $return;
}
/*
* acf_copy_postmeta
*
* This function will copy postmeta from one post to another.
* Very useful for saving and restoring revisions
*
* @type function
* @date 25/06/2016
* @since 5.3.8
*
* @param $from_post_id (int)
* @param $to_post_id (int)
* @return n/a
*/
function acf_copy_postmeta( $from_post_id, $to_post_id ) {
// get all postmeta
$meta = get_post_meta( $from_post_id );
// bail early if no meta
if( !$meta ) return;
// loop
foreach( $meta as $name => $value ) {
// attempt to find key value
$key = acf_maybe_get( $meta, '_'.$name );
// bail ealry if no key
if( !$key ) continue;
// update vars
$value = $value[0];
$key = $key[0];
// bail early if $key is a not a field_key
if( !acf_is_field_key($key) ) continue;
// get_post_meta will return array before running maybe_unserialize
$value = maybe_unserialize( $value );
// add in slashes
// - update_post_meta will unslash the value, so we must first slash it to avoid losing backslashes
// - https://codex.wordpress.org/Function_Reference/update_post_meta#Character_Escaping
if( is_string($value) ) {
$value = wp_slash($value);
}
// update value
acf_update_metadata( $to_post_id, $name, $value );
acf_update_metadata( $to_post_id, $name, $key, true );
}
}
/*
* acf_preview_value
*
* This function will return a human freindly 'preview' for a given field value
*
* @type function
* @date 24/10/16
* @since 5.5.0
*
* @param $value (mixed)
* @param $post_id (mixed)
* @param $field (array)
* @return (string)
*/
function acf_preview_value( $value, $post_id, $field ) {
// apply filters
$value = apply_filters( "acf/preview_value", $value, $post_id, $field );
$value = apply_filters( "acf/preview_value/type={$field['type']}", $value, $post_id, $field );
$value = apply_filters( "acf/preview_value/name={$field['_name']}", $value, $post_id, $field );
$value = apply_filters( "acf/preview_value/key={$field['key']}", $value, $post_id, $field );
// return
return $value;
}
?>