set_basename( false, __FILE__ ); } else { if ( !function_exists( 'acfb_fs' ) ) { function acfb_fs() { global $acfb_fs ; if ( !isset( $acfb_fs ) ) { // Include Freemius SDK. require_once dirname( __FILE__ ) . '/freemius/start.php'; $acfb_fs = fs_dynamic_init( array( 'id' => '3703', 'slug' => 'acf-blocks', 'premium_slug' => 'acf-blocks-pro', 'type' => 'plugin', 'public_key' => 'pk_5e62b729dd843294873241dcc6402', 'is_premium' => false, 'premium_suffix' => 'pro', 'has_addons' => false, 'has_paid_plans' => true, 'menu' => array( 'slug' => 'acf-blocks', 'support' => false, ), 'is_live' => true, ) ); } return $acfb_fs; } // Init Freemius. acfb_fs(); // Signal that SDK was initiated. do_action( 'acfb_fs_loaded' ); } if ( !function_exists( 'acfb_fs' ) ) { // Create a helper function for easy SDK access. function acfb_fs() { global $acfb_fs ; if ( !isset( $acfb_fs ) ) { // Include Freemius SDK. require_once dirname( __FILE__ ) . '/freemius/start.php'; $acfb_fs = fs_dynamic_init( array( 'id' => '3703', 'slug' => 'acf-blocks', 'premium_slug' => 'acf-blocks-pro', 'type' => 'plugin', 'public_key' => 'pk_5e62b729dd843294873241dcc6402', 'is_premium' => false, 'premium_suffix' => 'pro', 'has_addons' => false, 'has_paid_plans' => true, 'menu' => array( 'slug' => 'acf-blocks', ), 'is_live' => true, ) ); } return $acfb_fs; } // Init Freemius. acfb_fs(); // Signal that SDK was initiated. do_action( 'acfb_fs_loaded' ); } $free_blocks_init = plugin_dir_path( __FILE__ ) . 'free-acf-blocks.php'; $pro_blocks_init = plugin_dir_path( __FILE__ ) . 'pro-acf-blocks.php'; if ( file_exists( $free_blocks_init ) ) { require_once $free_blocks_init; } if ( file_exists( $pro_blocks_init ) ) { require_once $pro_blocks_init; } // Add Custom Blocks Panel in Gutenberg function acfb_block_categories( $categories, $post ) { return array_merge( $categories, array( array( 'slug' => 'acfb-blocks', 'title' => __( 'ACF Blocks', 'acfblocks-master' ), ) ) ); } add_filter( 'block_categories', 'acfb_block_categories', 10, 2 ); // Save Acf add_filter( 'acf/settings/save_json', 'acfb_json_save_point' ); function acfb_json_save_point( $acfb_path ) { // update path $acfb_path = plugin_dir_path( __FILE__ ) . '/acf-json'; // return return $acfb_path; } // Load Acf add_filter( 'acf/settings/load_json', 'acfb_json_load_point' ); function acfb_json_load_point( $acfb_path ) { // remove original path (optional) unset( $acfb_path[0] ); // append path $acfb_path[] = plugin_dir_path( __FILE__ ) . '/acf-json'; // return return $acfb_path; } // Excerpt Limit function acfb_excerpt( $acfb_excerpt_limit ) { $acfb_excerpt = explode( ' ', get_the_excerpt(), $acfb_excerpt_limit ); if ( count( $acfb_excerpt ) >= $acfb_excerpt_limit ) { array_pop( $acfb_excerpt ); $acfb_excerpt = implode( " ", $acfb_excerpt ) . '...'; } else { $acfb_excerpt = implode( " ", $acfb_excerpt ); } $acfb_excerpt = preg_replace( '`[[^]]*]`', '', $acfb_excerpt ); return $acfb_excerpt; } // Default Value in post List Elements add_filter( 'acf/load_value/name=acfb_post_list_elements', 'acfb_post_list_elements_defaults', 10, 3 ); function acfb_post_list_elements_defaults( $value, $post_id, $field ) { if ( $value !== NULL ) { // $value will only be NULL on a new post return $value; } // add default layouts $value = array( array( 'acf_fc_layout' => 'post_list_title', ), array( 'acf_fc_layout' => 'post_list_meta_data', ), array( 'acf_fc_layout' => 'post_list_content', ), array( 'acf_fc_layout' => 'post_list_read_more_button', ) ); return $value; } // Default Value in post Grid Elements add_filter( 'acf/load_value/name=acfb_post_grid_elements', 'acfb_post_grid_elements_defaults', 10, 3 ); function acfb_post_grid_elements_defaults( $value, $post_id, $field ) { if ( $value !== NULL ) { // $value will only be NULL on a new post return $value; } // add default layouts $value = array( array( 'acf_fc_layout' => 'post_grid_image', ), array( 'acf_fc_layout' => 'post_grid_title', ), array( 'acf_fc_layout' => 'post_grid_meta_data', ), array( 'acf_fc_layout' => 'post_grid_content', ), array( 'acf_fc_layout' => 'post_grid_read_more_button', ) ); return $value; } add_filter( 'acf/load_field/name=2_grid_layouts', 'acfb_two_grid_icons' ); function acfb_two_grid_icons( $field ) { $field['choices'] = array( 'one' => '', 'two' => '', ); return $field; } add_filter( 'acf/load_field/name=3_grid_layouts', 'acfb_three_grid_icons' ); function acfb_three_grid_icons( $field ) { $field['choices'] = array( 'one' => '', 'two' => '', 'three' => '', 'four' => '', 'five' => '', 'six' => '', ); return $field; } add_filter( 'acf/load_field/name=4_grid_layouts', 'acfb_four_grid_icons' ); function acfb_four_grid_icons( $field ) { $field['choices'] = array( 'one' => '', 'two' => '', 'three' => '', 'four' => '', 'five' => '', 'six' => '', 'seven' => '', 'eight' => '', 'nine' => '', 'ten' => '', 'eleven' => '', 'twelve' => '', 'thirteen' => '', 'fourteen' => '', 'fifteen' => '', ); return $field; } add_filter( 'acf/load_field/name=social_network', 'Social_icons' ); function Social_icons( $field ) { $field['choices'] = array( '1' => '', '2' => '', '3' => '', '4' => '', '5' => '', '6' => '', '7' => '', '8' => '', '9' => '', '10' => '', '11' => '', ); return $field; } add_filter( 'acf/load_field/name=acfb_post_tiled_collage_three_grid_layouts', 'acfb_post_tiled_three_grid_icons' ); function acfb_post_tiled_three_grid_icons( $field ) { $field['choices'] = array( 'one' => '', ); return $field; } add_filter( 'acf/load_field/name=acfb_post_tiled_collage_four_grid_layouts', 'acfb_post_tiled_four_grid_icons' ); function acfb_post_tiled_four_grid_icons( $field ) { $field['choices'] = array( 'one' => '', 'two' => '', ); return $field; } add_filter( 'acf/load_field/name=acfb_post_tiled_collage_five_grid_layouts', 'acfb_post_tiled_five_grid_icons' ); function acfb_post_tiled_five_grid_icons( $field ) { $field['choices'] = array( 'one' => '', 'two' => '', 'three' => '', ); return $field; } // Hexa Color Convert To Rgb or Rgba function hex2rgba( $color, $opacity = false ) { $default = 'rgb(0,0,0)'; //Return default if no color provided if ( empty($color) ) { return $default; } //Sanitize $color if "#" is provided if ( $color[0] == '#' ) { $color = substr( $color, 1 ); } //Check if color has 6 or 3 characters and get values if ( strlen( $color ) == 6 ) { $hex = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] ); } elseif ( strlen( $color ) == 3 ) { $hex = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] ); } else { return $default; } //Convert hexadec to rgb $rgb = array_map( 'hexdec', $hex ); //Check if opacity is set(rgba or rgb) if ( $opacity ) { if ( abs( $opacity ) > 1 ) { $opacity = 1.0; } $output = 'rgba(' . implode( ",", $rgb ) . ',' . $opacity . ')'; } else { $output = 'rgb(' . implode( ",", $rgb ) . ')'; } //Return rgb(a) color string return $output; } // Post type Select Box Filter function acfb_get_post_type( $field ) { $args = array( 'public' => true, ); $posttype = get_post_types( $args ); if ( in_array( "attachment", $posttype ) ) { unset( $posttype['attachment'] ); } $posttype_items = array(); foreach ( $posttype as $posttypeitem ) { $posttype_items[$posttypeitem] = $posttypeitem; } $field['choices'] = $posttype_items; return $field; } add_filter( 'acf/load_field/name=acfb_post_type', 'acfb_get_post_type' ); // Taxonomy Select Box Filter // function acfb_get_post_taxanomy( $field ) { // $taxonomies = get_object_taxonomies( 'post' ); // $tax_items = array(); // foreach($taxonomies as $taxonomy) { // $tax_items[] = $taxonomy; // } // $field['choices'] = $tax_items; // return $field; // } // add_filter('acf/load_field/name=acfb_taxonomy', 'acfb_get_post_taxanomy'); // Terms Select Box Filter // function acfb_get_post_terms( $field ) { // $terms = get_terms([ // 'taxonomy' => 'category', // 'hide_empty' => false, // ]); // $items = array(); // foreach($terms as $term) { // $items[] = $term->name; // } // $field['choices'] = $items; // return $field; // } // add_filter('acf/load_field/name=acfb_taxonomy_terms', 'acfb_get_post_terms'); // Template Overide function acf_blocks_template( $block ) { $acfb_temp = str_replace( "acf/", "", $block['name'] ); // Look for a file in theme if ( $theme_template = locate_template( 'acfblocks-templates/' . $acfb_temp . '.php' ) ) { require $theme_template; } else { // Nothing found, let's look in our plugin $free_template = plugin_dir_path( __FILE__ ) . 'acfblocks-templates/free/' . $acfb_temp . '.php'; $pro_template = plugin_dir_path( __FILE__ ) . 'acfblocks-templates/pro/' . $acfb_temp . '.php'; if ( file_exists( $free_template ) ) { require $free_template; } if ( file_exists( $pro_template ) ) { require $pro_template; } } } // Admin Page if ( file_exists( plugin_dir_path( __FILE__ ) . '/admin/class-acf-admin-page.php' ) ) { require_once plugin_dir_path( __FILE__ ) . '/admin/class-acf-admin-page.php'; } add_action( 'admin_enqueue_scripts', 'acfb_admin_styles' ); function acfb_admin_styles() { wp_enqueue_style( 'admin_css_foo', plugin_dir_url( __FILE__ ) . '/admin/admin-styles.css', false, '1.0.0' ); wp_enqueue_script( 'acfb_admin_scirpt', plugin_dir_url( __FILE__ ) . '/admin/admin-script.js', false, '' ); } function acfb_enqueue_scripts() { wp_enqueue_style( 'dashicons' ); } add_action( 'wp_enqueue_scripts', 'acfb_enqueue_scripts', 999 ); // Acf Custom field // check if class already exists if ( !class_exists( 'acfb_acf_plugin_typography' ) ) { class acfb_acf_plugin_typography { // vars var $settings ; function __construct() { // settings // - these will be passed into the field class. $this->settings = array( 'version' => '2.0.0', 'url' => plugin_dir_url( __FILE__ ), 'path' => plugin_dir_path( __FILE__ ), ); // include field add_action( 'acf/include_field_types', array( $this, 'include_field' ) ); // v5 add_action( 'acf/register_fields', array( $this, 'include_field' ) ); // v4 } function include_field( $version = false ) { // include include_once 'fields/class-acfb-acf-field-typography-v' . $version . '.php'; include_once 'fields/class-acfb-acf-field-padding-v' . $version . '.php'; include_once 'fields/class-acfb-acf-field-margin-v' . $version . '.php'; } } // initialize new acfb_acf_plugin_typography(); // class_exists check } function get_value( $field_id, $fields ) { $value = get_field( $field_id ); if ( is_null( $value ) ) { $defaults = get_field_object( $field_id ); $v = array(); foreach ( $fields as $field ) { $v[$field] = $defaults[$field] ?? ""; } return $v; } else { return $value; } } function build_css( $selectors ) { foreach ( $selectors as $key => $css ) { if ( $css !== 'default' and $css !== '' ) { echo $key . ':' . $css . ';' ; } } } function get_typo_field( $typo_name ) { ?> font-size: px; get_family( $typo_name['font_family'] ), 'font-weight' => $typo_name['font_weight'], 'text-transform' => $typo_name['font_transform'], 'font-style' => $typo_name['font_style'], 'text-decoration' => $typo_name['font_decoration'], ) ) ; ?> 0.1 ) { ?> line-height: ; letter-spacing: px; padding-top: px; padding-bottom: px; padding-left: px; padding-right: px; margin-top: px; margin-bottom: px; margin-left: px; margin-right: px; $field ) { if ( is_array( $field ) and array_key_exists( 'font_family', $field ) ) { $acfb_font_family = $field['font_family']; if ( $acfb_font_family !== "" and $acfb_font_family !== NULL and $acfb_font_family !== 'default' ) { $acfb_families[] = $acfb_font_family; } } } if ( !empty($acfb_families) ) { $family_merges = join( '&family=', $acfb_families ); return ""; } else { return ""; } } function get_family( $family ) { return str_replace( '+', " ", $family ); } function getCustomField( $field_name, $post_id ) { $selected_field = get_field( $field_name ); $selected_field_data = json_decode( $selected_field, true ); return [ 'type' => $selected_field_data['type'], 'value' => get_field( $selected_field_data['name'], $post_id ), ]; } // retrieves the attachment ID from the file URL for acf meta gallery function acfb_meta_gallery_get_image_id( $acfb_meta_gallery_image_url ) { global $wpdb ; $attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE guid='%s';", $acfb_meta_gallery_image_url ) ); return $attachment[0]; } } // freemius end