Пример #1
0
 /** 
  * Called via AJAX to submit the subscribe form. 
  *
  * @since 1.5.2
  * @return string The JSON encoded response.
  */
 public function submit()
 {
     $name = isset($_POST['name']) ? sanitize_text_field($_POST['name']) : false;
     $email = isset($_POST['email']) ? sanitize_email($_POST['email']) : false;
     $node_id = isset($_POST['node_id']) ? sanitize_text_field($_POST['node_id']) : false;
     $template_id = isset($_POST['template_id']) ? sanitize_text_field($_POST['template_id']) : false;
     $template_node_id = isset($_POST['template_node_id']) ? sanitize_text_field($_POST['template_node_id']) : false;
     $result = array('action' => false, 'error' => false, 'message' => false, 'url' => false);
     if ($email && $node_id) {
         // Get the module settings.
         if ($template_id) {
             $post_id = FLBuilderModel::get_node_template_post_id($template_id);
             $data = FLBuilderModel::get_layout_data('published', $post_id);
             $settings = $data[$template_node_id]->settings;
         } else {
             $module = FLBuilderModel::get_module($node_id);
             $settings = $module->settings;
         }
         // Subscribe.
         $instance = FLBuilderServices::get_service_instance($settings->service);
         $response = $instance->subscribe($settings, $email, $name);
         // Check for an error from the service.
         if ($response['error']) {
             $result['error'] = $response['error'];
         } else {
             $result['action'] = $settings->success_action;
             if ('message' == $settings->success_action) {
                 $result['message'] = $settings->success_message;
             } else {
                 $result['url'] = $settings->success_url;
             }
         }
     } else {
         $result['error'] = __('There was an error subscribing. Please try again.', 'fl-builder');
     }
     echo json_encode($result);
     die;
 }
Пример #2
0
 /**
  * Renders the custom CSS or JS for all global nodes in a layout. 
  *
  * @since 1.7
  */
 public static function render_global_nodes_custom_code($type = 'css')
 {
     $code = '';
     $rendered = array();
     if (!FLBuilderModel::is_post_node_template()) {
         $nodes = FLBuilderModel::get_layout_data();
         $node_status = FLBuilderModel::get_node_status();
         foreach ($nodes as $node_id => $node) {
             $template_post_id = FLBuilderModel::is_node_global($node);
             if ($template_post_id && !in_array($template_post_id, $rendered)) {
                 $rendered[] = $template_post_id;
                 $code .= FLBuilderModel::get_layout_settings($node_status, $template_post_id)->{$type};
             }
         }
     }
     return $code;
 }
 /**
  * Applies a node template that is defined as network-wide.
  *
  * @since 1.6.3
  * @param int $template_id The node template post ID.
  * @param string $parent_id The new parent node ID for the template.
  * @param int $position The position of the template within the layout.
  * @return void
  */
 public static function apply_node($template_id = null, $parent_id = null, $position = 0)
 {
     $site_id = self::get_source_site_id();
     $template = new StdClass();
     if ($site_id) {
         if (is_multisite()) {
             switch_to_blog($site_id);
         }
         $template->data = FLBuilderModel::get_layout_data('published', $template_id);
         $template->settings = FLBuilderModel::get_layout_settings('published', $template_id);
         $template->type = FLBuilderModel::get_user_template_type($template_id);
         $template->global = false;
         if (is_multisite()) {
             restore_current_blog();
         }
         return FLBuilderModel::apply_node_template($template_id, $parent_id, $position, $template);
     }
     return false;
 }