PATH:
var
/
www
/
vhosts
/
sandbox.dos-group.com
/
httpdocs
/
mendrisio
/
wp-content
/
plugins
/
vfbp-create-post
/
admin
<?php /** * The main function for the add-on * * @since 2.0 */ class VFB_Pro_Addon_Create_Post_Main { /** * title * * @var mixed * @access protected */ protected $title; /** * content * * @var mixed * @access protected */ protected $content; /** * excerpt * * @var mixed * @access protected */ protected $excerpt; /** * category * * @var mixed * @access protected */ protected $category; /** * tag * * @var mixed * @access protected */ protected $tag; /** * custom_field * * @var array * @access protected */ protected $custom_field = array(); /** * __construct function. * * @access public * @return void */ public function __construct() { add_action( 'vfbp_after_save_entry', array( $this, 'init' ), 10, 2 ); } /** * init function. * * @access public * @param mixed $entry_id * @param mixed $form_id * @return void */ public function init( $entry_id, $form_id ) { $vfbdb = new VFB_Pro_Data(); $settings = $vfbdb->get_addon_settings( $form_id ); $post_enable = isset( $settings['post-enable'] ) ? $settings['post-enable'] : ''; $post_type = isset( $settings['post-type'] ) ? $settings['post-type'] : 'post'; $post_status = isset( $settings['post-status'] ) ? $settings['post-status'] : 'draft'; $post_author = isset( $settings['post-author'] ) ? $settings['post-author'] : 1; // Exit if not enabled for this form if ( empty( $post_enable ) ) return; // Loop through entry data and set vars $meta = get_post_meta( $entry_id ); foreach ( $meta as $key => $value ) { $field_id = str_replace( '_vfb_field-', '', $key ); $this->set_vars( $field_id, $value[0] ); } // Submitted data $data = $this->get_vars(); // If any field is empty, output an error if ( empty( $data['post_title'] ) ) wp_die( __( 'Post title cannot be empty.', 'vfbp-create-post' ), '', array( 'back_link' => true ) ); // Set additional vars $data['post_type'] = $post_type; $data['post_status'] = $post_status; $data['post_author'] = $post_author; $post_id = wp_insert_post( $data, true ); // Return error if no title, content, or excerpt if ( is_wp_error( $post_id ) ) wp_die( $post_id, '', array( 'back_link' => true ) ); // Add category if ( !empty( $this->category ) ) wp_set_post_terms( $post_id, $this->category, 'category' ); // Add tags if ( !empty( $this->tag ) ) wp_set_post_terms( $post_id, $this->tag, 'post_tag' ); // Add custom fields if ( !empty( $this->custom_field ) ) $this->add_meta( $post_id, $this->custom_field ); } /** * get_vars function. * * @access private * @return void */ private function get_vars() { $data = array(); $data['post_title'] = !empty( $this->title ) ? $this->title : ''; $data['post_content'] = !empty( $this->content ) ? $this->content : ''; $data['post_excerpt'] = !empty( $this->excerpt ) ? $this->excerpt : ''; return $data; } /** * set_vars function. * * @access private * @param mixed $field_id * @param mixed $value * @return void */ private function set_vars( $field_id, $value ) { $field = $this->get_field_settings( $field_id ); $type = $field['field_type']; switch( $type ) { case 'post-title' : if ( !isset( $this->title ) ) $this->title = $value; break; case 'post-content' : if ( !isset( $this->content ) ) $this->content = $value; break; case 'post-excerpt' : if ( !isset( $this->excerpt ) ) $this->excerpt = $value; break; case 'post-category' : if ( !isset( $this->category ) ) $this->category = $value; break; case 'post-tag' : if ( !isset( $this->tag ) ) $this->tag = $value; break; case 'custom-field' : if ( !isset( $this->custom_field[ $field_id ] ) ) { $meta_key = isset( $field['data']['create-post-meta-key'] ) ? $field['data']['create-post-meta-key'] : ''; $this->custom_field[ $field_id ] = array( 'meta_key' => $meta_key, 'value' => $value, ); } break; } } /** * add_meta function. * * @access private * @param mixed $post_id * @param mixed $custom_field * @return void */ private function add_meta( $post_id, $custom_field ) { // Return if no post ID if ( 0 == $post_id ) return; // Custom fields should be an array if ( !is_array( $custom_field ) ) return; foreach ( $custom_field as $field_id => $data ) { $meta_key = $data['meta_key']; $value = $data['value']; if ( !empty( $meta_key ) ) { update_post_meta( $post_id, $meta_key, $value ); } } } /** * Get all field settings * * @access private * @param mixed $id * @return void */ private function get_field_settings( $id ) { $vfbdb = new VFB_Pro_Data(); $field = $vfbdb->get_field_by_id( $id ); return $field; } }
[-] class-create-post.php
[open]
[+]
..
[-] class-admin-settings.php
[open]
[-] index.php
[open]