This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //add_action( 'wp_print_scripts', 'sz_enqueue_scripts', 10); //run later or via wp_print_scripts ot catch all scripts | |
| add_action( 'wp_enqueue_scripts', 'sz_enqueue_scripts', 999); | |
| function sz_enqueue_scripts(){ | |
| global $wp_scripts; | |
| //change dependency to load earlier | |
| $handles_to_filter = array('dt-above-fold'); | |
| $dependency_handle_to_add = 'wpb_composer_front_js'; //TODO: accept array | |
| foreach ($handles_to_filter as $handle_to_filter){ | |
| foreach( $wp_scripts->registered as $script_object) { //find script in registered by handle | |
| if ($script_object->handle == $handle_to_filter){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Plugin Name: SZ WP REST API Tutorial | |
| * Description: It's an example of WP REST API usage for search with autocomplete with vanilla JS | |
| * Plugin URI: | |
| * Author: Sabrina Zeidan | |
| * Author URI: https://sabrinazeidan.com | |
| * License: GNU General Public License v2 or later | |
| * License URI: http://www.gnu.org/licenses/gpl-2.0.html | |
| * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //This filters display, but CSS and JS are still loaded | |
| add_filter( 'addtoany_script_disabled', 'addtoany_disable_display' ); | |
| function addtoany_disable_display($script_disabled) { | |
| if ( is_front_page() || is_archive() ) { | |
| return true; | |
| } else { | |
| return $script_disabled; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //If both changed at the same time - custom field value will be applied as it fires later, set 30 to change it add_action( 'profile_update', array($this, 'update_acf_fields'), 30, 2 ); | |
| class Sync_ACF_with_User_Profile_Class { | |
| static public $sync_pair = array( | |
| array( 'acf' => 'member_name', 'profile_field' => 'first_name'), //add acf field name according to your setup | |
| array( 'acf' => 'member_lastname', 'profile_field' => 'last_name')// add more rows to sync any other fields as well | |
| ); | |
| public function __construct() { | |
| add_action( 'profile_update', array($this, 'update_acf_fields'), 10, 2 ); //when profile is updated -> update ACF | |
| add_action('updated_user_meta', array($this, 'update_user_profile_fields'),10,4); // when ACF is updated -> update profile | |
| add_action('added_user_meta', array($this, 'update_user_profile_fields'),10,4); // when ACF is added -> update profile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // get all field groups that have location User Add/Edit Form | |
| $field_groups = acf_get_field_groups(array( 'user_form' => 'edit')); | |
| $all_fields = array(); | |
| foreach ($field_groups as $field_group){ | |
| $fields = acf_get_fields($field_group['key']); | |
| $all_fields = array_merge($all_fields, $fields); //get all user's fields together | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_shortcode( 'acf_registration', 'acf_registration' ); | |
| function acf_registration() { | |
| $args = array(); //arguments here | |
| ob_start(); | |
| acf_form( $args ); | |
| $registration_form = ob_get_contents(); | |
| ob_end_clean(); | |
| return $registration_form; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //<div class="elementor-column"><div class="dce-acf-repater-"><div class="repeater-item"></div></div><div class="elementor-widget-button"></div></div> | |
| (function( $ ){ | |
| $(".elementor-column .dce-acf-repater-").each(function() { | |
| if (!$(this).has(".repeater-item").length) { | |
| hide = $(this).closest('.elementor-column').find(".elementor-widget-button").hide(); | |
| } | |
| }); | |
| })(jQuery); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //custom-query-name is set in Elementor as query ID | |
| add_action( 'elementor/query/custom-query-name', function( $query ) { | |
| $meta_query = (array)$query->get('meta_query'); | |
| $meta_query[] = array( | |
| 'key' => 'custom_field', | |
| 'value' => '', | |
| 'compare' => '!=', | |
| ); | |
| $query->set('meta_query',$meta_query); | |
| } ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| //Handy when CPT previews are used in different templates across the site | |
| add_action( 'loop_start', 'recipes_loop_start' ); | |
| function recipes_loop_start( $query ){ | |
| if ( !$query->is_main_query() && $query->get('post_type')== 'recipe' && !is_admin()) echo "<ul class='recipes-preview'>"; | |
| } | |
| add_action( 'loop_end', 'recipes_loop_end' ); | |
| function recipes_loop_end( $query ){ | |
| if ( !$query->is_main_query() && $query->get('post_type')== 'recipe' && !is_admin()) echo "</ul>"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| //Examples of input | |
| $input = "http://www.example.com/cat/cat-child/slug/"; | |
| $input = "http://www.example.com/cat/slug"; | |
| $input = "http://www.example.com/cat/slug/"; | |
| $input = "http://www.example.com/cat/slug/?dsss&efsdc=dc"; | |
| //This line will always return "slug" | |
| $slug = basename(strtok(str_replace(' ', '', htmlspecialchars($input )), '?')).PHP_EOL; | |
| echo $slug; | |
| //Useful for further use with get_term_by('slug', $slug, $tax); |