Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/themify-.../themify/themify-.../includes
File: themify-metabox-utils.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Takes an array of options and return a one dimensional array of all the field names
[3] Fix | Delete
*
[4] Fix | Delete
* @return array
[5] Fix | Delete
* @since 1.0.2
[6] Fix | Delete
*/
[7] Fix | Delete
function themify_metabox_get_field_names( $arr ) {
[8] Fix | Delete
$list = array();
[9] Fix | Delete
if( ! empty( $arr ) ){
[10] Fix | Delete
foreach( $arr as $metabox ){
[11] Fix | Delete
if( ! empty( $metabox['options'] ) ) {
[12] Fix | Delete
$options = themify_metabox_make_flat_fields_array( $metabox['options'] );
[13] Fix | Delete
$options = array_filter( $options, function ( $item ) {
[14] Fix | Delete
if ( isset( $item['name'] ) )
[15] Fix | Delete
return true;
[16] Fix | Delete
return false;
[17] Fix | Delete
} );
[18] Fix | Delete
$list = array_merge( $list, wp_list_pluck( $options, 'name' ) );
[19] Fix | Delete
}
[20] Fix | Delete
}
[21] Fix | Delete
}
[22] Fix | Delete
[23] Fix | Delete
return apply_filters( 'themify_metabox_get_field_names', array_keys(array_flip( $list )), $arr );
[24] Fix | Delete
}
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* Takes an options array and returns a one-dimensional list of fields
[28] Fix | Delete
*
[29] Fix | Delete
* @return array
[30] Fix | Delete
* @since 1.0.2
[31] Fix | Delete
*/
[32] Fix | Delete
function themify_metabox_make_flat_fields_array( $arr ) {
[33] Fix | Delete
$list = array();
[34] Fix | Delete
foreach ( $arr as $field ) {
[35] Fix | Delete
if ( ! isset( $field['type'] ) ) {
[36] Fix | Delete
continue;
[37] Fix | Delete
}
[38] Fix | Delete
if ( $field['type'] === 'multi' ) {
[39] Fix | Delete
foreach ( $field['meta']['fields'] as $_field ) {
[40] Fix | Delete
$list[] = $_field;
[41] Fix | Delete
}
[42] Fix | Delete
} elseif ( $field['type'] === 'toggle_group' ) {
[43] Fix | Delete
foreach ( $field['meta'] as $_field ) {
[44] Fix | Delete
$list[] = $_field;
[45] Fix | Delete
}
[46] Fix | Delete
} else {
[47] Fix | Delete
$list[] = $field;
[48] Fix | Delete
}
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
return $list;
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
/**
[55] Fix | Delete
* Check if assignments are applied in the current context
[56] Fix | Delete
*
[57] Fix | Delete
* @since 1.0
[58] Fix | Delete
*/
[59] Fix | Delete
function themify_verify_assignments( $assignments ) {
[60] Fix | Delete
$query_object = get_queried_object();
[61] Fix | Delete
[62] Fix | Delete
if ( ! empty( $assignments['roles'] )
[63] Fix | Delete
// check if *any* of user's role(s) matches
[64] Fix | Delete
&& ! count( array_intersect( wp_get_current_user()->roles, array_keys( $assignments['roles'], true ) ) )
[65] Fix | Delete
) {
[66] Fix | Delete
return false; // bail early.
[67] Fix | Delete
}
[68] Fix | Delete
unset( $assignments['roles'] );
[69] Fix | Delete
[70] Fix | Delete
if ( ! empty($assignments ) ) {
[71] Fix | Delete
[72] Fix | Delete
[73] Fix | Delete
if (
[74] Fix | Delete
( isset($assignments['general']['home']) && is_front_page())
[75] Fix | Delete
|| (isset( $assignments['general']['page'] ) && is_page() && ! is_front_page() )
[76] Fix | Delete
|| ( is_singular('post') && isset($assignments['general']['single']) )
[77] Fix | Delete
|| ( isset($assignments['general']['search']) && is_search() )
[78] Fix | Delete
|| ( isset($assignments['general']['author']) && is_author())
[79] Fix | Delete
|| ( isset($assignments['general']['category']) && is_category())
[80] Fix | Delete
|| ( isset($assignments['general']['tag']) && is_tag())
[81] Fix | Delete
|| ( isset($query_object->post_type,$assignments['general'][$query_object->post_type]) && is_singular() && $query_object->post_type !== 'page' && $query_object->post_type !== 'post' )
[82] Fix | Delete
|| ( isset($query_object->taxonomy,$assignments['general'][$query_object->taxonomy]) && is_tax())
[83] Fix | Delete
) {
[84] Fix | Delete
return true;
[85] Fix | Delete
} else { // let's dig deeper into more specific visibility rules
[86] Fix | Delete
if ( ! empty( $assignments['tax'] ) ) {
[87] Fix | Delete
if ( is_single() ) {
[88] Fix | Delete
if ( ! empty( $assignments['tax']['category_single'] ) ) {
[89] Fix | Delete
$categories = wp_get_post_categories( get_queried_object_id(), array( 'fields' => 'slugs' ) );
[90] Fix | Delete
if ( array_intersect( array_keys( $assignments['tax']['category_single'], true ), $categories ) ) {
[91] Fix | Delete
return true;
[92] Fix | Delete
}
[93] Fix | Delete
}
[94] Fix | Delete
} else {
[95] Fix | Delete
foreach ( $assignments['tax'] as $tax => $terms ) {
[96] Fix | Delete
$terms = array_keys( $terms );
[97] Fix | Delete
if ( ( $tax === 'category' && is_category($terms) ) || ( $tax === 'post_tag' && is_tag( $terms ) ) || ( is_tax( $tax, $terms ) )
[98] Fix | Delete
) {
[99] Fix | Delete
return true;
[100] Fix | Delete
}
[101] Fix | Delete
}
[102] Fix | Delete
}
[103] Fix | Delete
}
[104] Fix | Delete
if (! empty( $assignments['post_type'] ) ) {
[105] Fix | Delete
foreach ( $assignments['post_type'] as $post_type => $posts ) {
[106] Fix | Delete
$posts = array_keys( $posts );
[107] Fix | Delete
[108] Fix | Delete
/* child pages have unique names based on their permalink */
[109] Fix | Delete
if ( $post_type === 'page' && ! empty( $query_object->post_parent ) ) {
[110] Fix | Delete
$post_name = str_replace( home_url(), '', get_permalink( $query_object->ID ) );
[111] Fix | Delete
if ( in_array( $post_name, $posts ) ) {
[112] Fix | Delete
return true;
[113] Fix | Delete
}
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
if (
[117] Fix | Delete
// Post single
[118] Fix | Delete
( $post_type === 'post' && is_single() && is_single( $posts ) )
[119] Fix | Delete
// Page view
[120] Fix | Delete
|| ( $post_type === 'page' && (
[121] Fix | Delete
( is_page( $posts ) )
[122] Fix | Delete
|| ( ! is_front_page() && is_home() && in_array( get_post_field( 'post_name', get_option( 'page_for_posts' ) ), $posts ,true ) ) // check for Posts page
[123] Fix | Delete
|| ( themify_metabox_is_shop() && in_array( get_post_field( 'post_name', themify_metabox_shop_pageId()), $posts,true ) ) // check for Shop page
[124] Fix | Delete
) )
[125] Fix | Delete
// Custom Post Types single view check
[126] Fix | Delete
|| ( is_singular( $post_type ) && in_array( $query_object->post_name, $posts,true ) )
[127] Fix | Delete
) {
[128] Fix | Delete
return true;
[129] Fix | Delete
}
[130] Fix | Delete
}
[131] Fix | Delete
}
[132] Fix | Delete
}
[133] Fix | Delete
}
[134] Fix | Delete
return false;
[135] Fix | Delete
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
/**
[139] Fix | Delete
* Take an array and converts it to multiple input[type="hidden"]
[140] Fix | Delete
*
[141] Fix | Delete
* @return string
[142] Fix | Delete
*/
[143] Fix | Delete
function themify_array_to_input( $array, $prefix = '' ) {
[144] Fix | Delete
$output = '';
[145] Fix | Delete
if (count( array_filter( array_keys( $array ), 'is_string' ) ) ) {
[146] Fix | Delete
foreach ( $array as $key => $value ) {
[147] Fix | Delete
if ( empty( $prefix ) ) {
[148] Fix | Delete
$name = $key;
[149] Fix | Delete
} else {
[150] Fix | Delete
$name = $prefix . '[' . $key . ']';
[151] Fix | Delete
}
[152] Fix | Delete
if ( is_array( $value ) ) {
[153] Fix | Delete
$output .= themify_array_to_input( $value, $name );
[154] Fix | Delete
} else {
[155] Fix | Delete
$output .= '<input type="hidden" value="' . $value .'" name="' . $name .'">';
[156] Fix | Delete
}
[157] Fix | Delete
}
[158] Fix | Delete
} else {
[159] Fix | Delete
foreach ($array as $item) {
[160] Fix | Delete
if ( is_array($item) ) {
[161] Fix | Delete
$output .= themify_array_to_input( $item, $prefix . '[]' );
[162] Fix | Delete
} else {
[163] Fix | Delete
$output .= '<input type="hidden" name="' . $prefix . '[]" value="' . $item .'">';
[164] Fix | Delete
}
[165] Fix | Delete
}
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
return $output;
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
/**
[172] Fix | Delete
* Checks if Woocommerce plugin is active and returns the proper value
[173] Fix | Delete
*
[174] Fix | Delete
* @return bool
[175] Fix | Delete
*/
[176] Fix | Delete
function themify_metabox_is_woocommerce_active() {
[177] Fix | Delete
if(function_exists('themify_is_woocommerce_active')){
[178] Fix | Delete
return themify_is_woocommerce_active();
[179] Fix | Delete
}
[180] Fix | Delete
static $is = null;
[181] Fix | Delete
if ( $is===null ) {
[182] Fix | Delete
$plugin = 'woocommerce/woocommerce.php';
[183] Fix | Delete
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
[184] Fix | Delete
return is_plugin_active( $plugin )
[185] Fix | Delete
// validate if $plugin actually exists, the plugin might be active however not installed.
[186] Fix | Delete
&& is_file( trailingslashit( WP_PLUGIN_DIR ) . $plugin );
[187] Fix | Delete
}
[188] Fix | Delete
return $is;
[189] Fix | Delete
}
[190] Fix | Delete
[191] Fix | Delete
/**
[192] Fix | Delete
* Returns the ID of the designated Shop page in WC plugin
[193] Fix | Delete
*
[194] Fix | Delete
* @return false|int
[195] Fix | Delete
*/
[196] Fix | Delete
function themify_metabox_shop_pageId(){
[197] Fix | Delete
if(function_exists('themify_shop_pageId')){
[198] Fix | Delete
return themify_shop_pageId();
[199] Fix | Delete
}
[200] Fix | Delete
static $id = null;
[201] Fix | Delete
if ( $id === null ) {
[202] Fix | Delete
if ( themify_metabox_is_woocommerce_active() ) {
[203] Fix | Delete
$id = wc_get_page_id( 'shop' );
[204] Fix | Delete
if ( $id <= 0 ) { //wc bug, page id isn't from wc settings,the default should be page with slug 'shop'
[205] Fix | Delete
$page = get_page_by_path( 'shop' );
[206] Fix | Delete
$id = ! empty( $page ) ? (int) $page->ID : false;
[207] Fix | Delete
}
[208] Fix | Delete
} else {
[209] Fix | Delete
$id = false;
[210] Fix | Delete
}
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
return $id;
[214] Fix | Delete
}
[215] Fix | Delete
[216] Fix | Delete
[217] Fix | Delete
function themify_metabox_is_shop(){
[218] Fix | Delete
if(function_exists('themify_is_shop')){
[219] Fix | Delete
return themify_is_shop();
[220] Fix | Delete
}
[221] Fix | Delete
return themify_metabox_is_woocommerce_active() && is_shop();
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
function themify_metabox_enque($url){//backward
[225] Fix | Delete
return $url;
[226] Fix | Delete
}
[227] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function