Advertisement
palsushobhan

ACF-integrated-within-theme

Jan 6th, 2024
842
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.84 KB | None | 0 0
  1. function is_acf_part_of_theme() {
  2.     return (
  3.         class_exists('ACF') &&
  4.         apply_filters('wcfm_is_allow_acf_fields', true) &&
  5.         !WCFMu_Dependencies::wcfm_acf_pro_active_check() &&
  6.         !WCFMu_Dependencies::wcfm_acf_active_check()
  7.     );
  8. }
  9.  
  10. add_action('wcfm_init', function() {
  11.     if (is_acf_part_of_theme()) {
  12.         global $WCFMu;
  13.        
  14.         // Advanced Custom Fields(ACF) Pro - Products Support - 3.3.7
  15.         add_action('after_wcfm_products_manage_tabs_content', [ $WCFMu->wcfmu_integrations, 'wcfm_acf_pro_product_manage_fields' ], 60);
  16.         add_action('end_wcfm_articles_manage', [ $WCFMu->wcfmu_integrations, 'wcfm_acf_pro_article_manage_fields' ], 160);
  17.  
  18.         // Advanced Custom Fields(ACF) Pro - Profile Support - 6.5.2
  19.         if (wcfm_is_vendor()) {
  20.             add_action('end_wcfm_user_profile', [ $WCFMu->wcfmu_integrations, 'wcfmmp_profile_acf_info' ], 80);
  21.         }
  22.  
  23.         add_action('after_wcfm_vendors_manage_form', [ $WCFMu->wcfmu_integrations, 'wcfmmp_profile_acf_info' ], 12);
  24.         add_action('wcfm_profile_update', [ $WCFMu->wcfmu_integrations, 'wcfmmp_profile_acf_info_update' ], 75, 2);
  25.         add_action('wcfm_vendor_manage_profile_update', [ $WCFMu->wcfmu_integrations, 'wcfmmp_profile_acf_info_update' ], 75, 2);
  26.  
  27.         add_action('wcfm_load_scripts', 'wcfm_load_acf_scripts', 81);
  28.         add_action('after_wcfm_load_scripts', 'wcfm_load_acf_scripts', 81);
  29.  
  30.         add_action('after_wcfm_ajax_controller', 'wcfm_acf_ajax_controller', 11);
  31.  
  32.     }//end if
  33. }, 13);
  34.  
  35. function wcfm_load_acf_scripts($endpoints) {
  36.     global $WCFM, $WCFMu;
  37.     switch ($endpoints) {
  38.         case 'wcfm-articles-manage':
  39.             $WCFM->library->load_timepicker_lib();
  40.             wp_enqueue_script('wcfmu_acf_pro_articles_manage_js', $WCFMu->library->js_lib_url.'integrations/acf/wcfmu-script-acf-pro-articles-manage.js', [ 'jquery', 'wcfm_articles_manage_js' ], $WCFMu->version, true);
  41.  
  42.             $scheme      = is_ssl() ? 'https' : 'http';
  43.             $acf_map_key = acf_get_setting('google_api_key');
  44.             if ($acf_map_key) {
  45.                 wp_enqueue_script('jquery-ui-autocomplete');
  46.                 wp_enqueue_script('wcfm-acf-pro-pm-google-maps', $scheme.'://maps.googleapis.com/maps/api/js?key='.$acf_map_key.'&libraries=places');
  47.             }
  48.             break;
  49.         case 'wcfm-products-manage':
  50.             $WCFM->library->load_timepicker_lib();
  51.             wp_enqueue_script('wcfmu_acf_pro_products_manage_js', $WCFMu->library->js_lib_url.'integrations/acf/wcfmu-script-acf-pro-products-manage.js', [ 'jquery', 'wcfm_products_manage_js' ], $WCFMu->version, true);
  52.  
  53.             $scheme      = is_ssl() ? 'https' : 'http';
  54.             $acf_map_key = acf_get_setting('google_api_key');
  55.             if ($acf_map_key) {
  56.                 wp_enqueue_script('jquery-ui-autocomplete');
  57.                 wp_enqueue_script('wcfm-acf-pro-pm-google-maps', $scheme.'://maps.googleapis.com/maps/api/js?key='.$acf_map_key.'&libraries=places');
  58.             }
  59.             break;
  60.     }
  61. }
  62.  
  63. function wcfm_acf_ajax_controller() {
  64.     //skipped nonce check as loaded with 11 priority after wcfmu_thirdparty_ajax_controller (10)
  65.     global $WCFMu;
  66.     if (isset($_POST['controller'])) {
  67.         $controllers_path = $WCFMu->plugin_path.'controllers/integrations/';
  68.         $controller = $_POST['controller'];
  69.         switch ($controller) {
  70.             case 'wcfm-articles-manage':
  71.                 include_once $controllers_path.'acf/wcfmu-controller-acf-pro-articles-manage.php';
  72.                 new WCFMu_ACF_Pro_Articles_Manage_Controller();
  73.                 break;
  74.             case 'wcfm-products-manage':
  75.                 include_once $controllers_path.'acf/wcfmu-controller-acf-pro-products-manage.php';
  76.                 new WCFMu_ACF_Pro_Products_Manage_Controller();
  77.                 break;
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement