get_field_name( $name ) : $name_attr_pre . $frag );
}
/**
* Construct id for use on shortcode and widget options pages.
*
* A wrapper used to create an id. if displaying options for a widget, uses the widgets' get_field_id method.
*
* @since 1.0.0
*
* @param string $id Required. Id of input field.
* @param string $name_attr_pre Optional. Prefix for id attribute.
* @param object $widget Optional. Widget object if displaying options for a widget.
* @return string. Modified name of input field.
*/
public function get_field_id_wrap( $id, $name_attr_pre = '', & $widget = false ) {
return ( $widget ? $widget->get_field_id( $id ) : $name_attr_pre . '-' . $id );
}
/**
* Construct the html to upload an image
*
* @since 1.0.0
*
* @param array $opts Optional. Saved options, if any.
* @param string $name Required. Name of the input field.
*/
function construct_upload_image( $opts, $name ) {
if ( ! isset( $name ) ) {
return;
}
?>
/>
/>
/>
/>
get_field_name_wrap( 'title_text', "fourbzcore[$name]", $widget ) . "' />";
// These options are not relevant to these shortcodes and widgets.
if ( ! in_array( $opts['name'], array( 'slideshow', 'contact_form', 'contact_info', 'progressbars', 'image_text', 'author_bio', 'column' ) ) ) {
$html_str .= " get_field_name_wrap( 'limit', "fourbzcore[$name]", $widget ) . "' />";
}
$html_str .= "";
return $html_str;
}
/**
* 2.3.3.3 Posts Options
*-----------------------------------------------------------------------*/
/**
* Construct and display options for posts. Used by the featured, recent, related, and popular posts shortcodes and widgets.
*
* Apply the fourbzcore_options_posts filters on the options.
*
* @since 1.0.0
*
* @param string $component Required. Name of shortcode or widget whose options are being displayed.
* @param array $opts Optional. Only relative if displaying a widget's options because these shortcode options are not saved to the database, they are used in the shortcode builder to generate the shortcode string.
* @param object $widget Optional. Widget object if displaying options for a widget.
*/
public function display_options_posts( $component, $opts = array(), & $widget = false ) {
if ( ! isset( $component ) ) {
return;
}
$opts['name'] = $component;
$opts_str = '
';
return apply_filters( '4bzcore_options_posts', $opts_str, $component, $opts, $widget );
}
/**
* Construct and display options for the featured posts shortcode and widget.
*
* Apply the fourbzcore_options_featured_posts filters on the options.
*
* @since 1.0.0
*
* @param array $opts Optional. Only relative if displaying a widget's options because these shortcode options are not saved to the database, they are used in the shortcode builder to generate the shortcode string.
* @param object $widget Optional. Widget object if displaying options for a widget.
*/
public function display_options_featured_posts( $opts = array(), & $widget = false ) {
$opts_str = '
';
echo apply_filters( '4bzcore_options_featured_posts', $opts_str, $opts, $widget );
}
/**
* Construct and display options for related posts shortcode and widget.
*
* Apply the fourbzcore_options_related_posts filters on the options.
*
* @since 1.0.0
*
* @param array $opts Optional. Only relative if displaying a widget's options because these shortcode options are not saved to the database, they are used in the shortcode builder to generate the shortcode string.
* @param object $widget Optional. Widget object if displaying options for a widget.
*/
public function display_options_related_posts( $opts = array(), & $widget = false ) {
$opts_str = '
';
echo apply_filters( '4bzcore_options_related_posts', $opts_str, $opts, $widget );
}
/**
* Construct and display options for recent posts shortcode and widget.
*
* Apply the fourbzcore_options_recent_posts filters on the options.
*
* @since 1.0.0
*
* @param array $opts Optional. Only relative if displaying a widget's options because these shortcode options are not saved to the database, they are used in the shortcode builder to generate the shortcode string.
* @param object $widget Optional. Widget object if displaying options for a widget.
*/
public function display_options_recent_posts( $opts = array(), & $widget = false ) {
$opts_str = '
';
echo apply_filters( '4bzcore_options_recent_posts', $opts_str, $opts, $widget );
}
/**
* Construct and display options for popular posts shortcode and widget.
*
* Apply the fourbzcore_options_popular_posts filters on the options.
*
* @since 1.0.0
*
* @param array $opts Optional. Only relative if displaying a widget's options because these shortcode options are not saved to the database, they are used in the shortcode builder to generate the shortcode string.
* @param object $widget Optional. Widget object if displaying options for a widget.
*/
public function display_options_popular_posts( $opts = array(), & $widget = false ) {
$opts_str = '
';
echo apply_filters( '4bzcore_options_popular_posts', $opts_str, $opts, $widget );
}
/**
* 2.3.3.4 Shortcodes + Widgets Options: Not Post Based
*-----------------------------------------------------------------------*/
/**
* Construct and display options for facebook comments shortcode and widget.
*
* Apply the fourbzcore_options_facebook_comments filters on the options.
*
* @since 1.0.0
*
* @param array $opts Optional. Only relative if displaying a widget's options because these shortcode options are not saved to the database, they are used in the shortcode builder to generate the shortcode string.
* @param object $widget Optional. Widget object if displaying options for a widget.
*/
public function display_options_facebook_comments( $opts = array(), & $widget = false ) {
$opts['name'] = 'facebook_comments';
$opts_str = "
';
echo apply_filters( '4bzcore_options_facebook_comments', $opts_str, $opts, $widget );
}
/**
* Construct and display options for the flickr photos shortcode and widget.
*
* Apply the fourbzcore_options_flickr_photos filters on the options.
*
* @since 1.0.0
*
* @param array $opts Optional. Only relative if displaying a widget's options because these shortcode options are not saved to the database, they are used in the shortcode builder to generate the shortcode string.
* @param object $widget Optional. Widget object if displaying options for a widget.
*/
public function display_options_flickr_photos( $opts = array(), & $widget = false ) {
$opts['name'] = 'flickr_photos';
$opts_str = '';
$opts_str .= "
' . __( 'Image Text Specific Options', $this->txt_domain ) . '
';
echo apply_filters( '4bzcore_options_image_text', $opts_str, $opts, $widget );
}
/**
* Construct and display options for the author bio shortcode and widget.
*
* Apply the fourbzcore_options_author_bio filters on the options.
*
* @since 1.0.0
*
* @param array $opts Optional. Only relative if displaying a widget's options because these shortcode options are not saved to the database, they are used in the shortcode builder to generate the shortcode string.
* @param object $widget Optional. Widget object if displaying options for a widget.
*/
public function display_options_author_bio( $opts = array(), & $widget = false ) {
$opts['name'] = 'author_bio';
$opts_str = "
';
echo apply_filters( '4bzcore_options_author_bio', $opts_str, $opts, $widget );
}
/**
* Construct and display options for the column shortcode.
*
* Apply the fourbzcore_options_column filters on the options.
*
* @since 1.0.0
*
* @param array $opts Optional. Only relative if displaying a widget's options because these shortcode options are not saved to the database, they are used in the shortcode builder to generate the shortcode string.
* @param object $widget Optional. Widget object if displaying options for a widget.
*/
public function display_options_column( $opts = array(), & $widget = false ) {
$opts['name'] = 'column';
$opts_str = '';
$opts_str .= "
';
echo apply_filters( '4bzcore_options_column', $opts_str, $opts, $widget );
}
/**
* 2.3.4 Tinymce + Shortcode Builder
*-----------------------------------------------------------------------*/
/**
* Add filters to add a custom button to the tinymce menu.
*
* @since 1.0.0
*/
public function shortcode_builder_tinymce_buttons() {
// Load the tinymce plugin
add_filter( 'mce_external_plugins', array( $this, 'shortcode_builder_register_tinymce_js' ) );
// Add new buttons
add_filter( 'mce_buttons', array( $this, 'shortcode_builder_register_buttons' ) );
}
/**
* Function that actually adds the plugin's custom button to array of buttons on the tinymce menu.
*
* @since 1.0.0
*
* @param array $buttons Required. Array of tinymce buttons.
* @return array $buttons. Array of tinymce buttons, augmented with the plugin's tinymce button.
*
*/
public function shortcode_builder_register_buttons( $buttons ) {
array_push( $buttons, 'fourbzcore_shortcodebuilder' );
return $buttons;
}
/**
* Register the javascript file that handles the tinymce actions for plugin's custom button.
*
* @since 1.0.0
*
* @param array $plugin_array Required. Array of tinymce plugins.
* @return array $plugin_array. Array of tinymce plugins, augmented with the plugin's plugin.
*/
public function shortcode_builder_register_tinymce_js( $plugin_array ) {
$plugin_array['fourbzcore_shortcodebuilder'] = $this->plugin_url . 'js/4bzcore-tinymce.js';
return $plugin_array;
}
/**
* Change the encoding.
*
* @since 1.0.0
*
* @param array $init_array Required. Array of initialization data.
*/
public function change_mce_options( $init_array ) {
$init_array['entity_encoding'] = 'named';
return $init_array;
}
/**
* Construct and display options for the shortcode builder.
*
* Each shortcode has a function to output its options. Format of the method is
* display_options_$shortcode().
*
* @since 1.0.0
*
* @param string $shortcode Optional. If set, then display options for shortcode, otherwise display a select field to choose a shortcode.
*/
public function shortcode_options( $shortcode = '' ) {
$shortcode_options = '';
echo "
';
}
/**
* 2.3.5 Post Edit Page
*-----------------------------------------------------------------------*/
/**
* Add metaboxes to post and page edit screens for related posts.
*
* @since 1.0.0
*/
public function add_meta_boxes() {
$screens = array( 'post', 'page', 'product' );
foreach ( $screens as $screen ) {
add_meta_box(
$this->page_slug,
__( '4bzCore Post Options', $this->txt_domain ),
array( $this, 'display_media_meta_boxes' ),
$screen,
'side'
);
}
}
/**
* Construct and display a meta box that contains options for related posts.
*
* @since 1.0.0
*
* @param WP_Post $post The object for the current post/page.
*/
public function display_meta_boxes( $post ) {
$i = 0;
// Add a nonce field so we can check for it later.
wp_nonce_field( $this->plugin_prefix . '_display_meta_box', $this->plugin_prefix . '_display_meta_box_nonce' );
// Get the saved data.
$opts = get_post_meta( $post->ID, $this->db_options_name, true );
$this->display_related_meta_box( isset( $opts['related'] ) ? $opts['related'] : '' );
echo '';
}
/**
* Construct and display options for related posts to be displayed in the meta box
*
* @since 1.0.0
*
* @param string $related Optional. Saved related posts.
*/
public function display_related_meta_box( $related ) {
echo '
' .
__( 'Related Posts', $this->txt_domain ) . '
';
}
/**
* Construct and display a meta box that contains options for media
*
* @since 1.0.0
*
* @param WP_Post $post The object for the current post/page.
*/
public function display_media_meta_boxes( $post ) {
$i = 0;
// Use get_post_meta() to retrieve an existing value.
echo '
" . __( 'Sort the skills by hovering over a skill until a hand appears, drag and drop where desired.', $this->txt_domain ) . '
' . $skills_html . '
';
echo '
';
}
/**
* Save custom fields for user
*
* @since 1.0.0
*
* @param int $user_id Required. Id of user.
*/
public function save_user_cfs( $user_id ) {
if ( ! isset( $user_id ) ) {
return;
}
$fourbzcore_cust_fields = array();
$fourbzcore_cust_fields['title'] = sanitize_text_field( $_POST['fourbzcore']['title'] );
$fourbzcore_cust_fields['contact_address'] = $_POST['fourbzcore']['contact_address'];
$fourbzcore_cust_fields['contact_phone'] = $_POST['fourbzcore']['contact_phone'];
$fourbzcore_cust_fields['contact_facebook'] = esc_url_raw( $_POST['fourbzcore']['contact_facebook'] );
$fourbzcore_cust_fields['contact_twitter'] = esc_url_raw( $_POST['fourbzcore']['contact_twitter'] );
$fourbzcore_cust_fields['contact_google'] = esc_url_raw( $_POST['fourbzcore']['contact_google'] );
$fourbzcore_cust_fields['contact_linkedin'] = esc_url_raw( $_POST['fourbzcore']['contact_linkedin'] );
$fourbzcore_cust_fields['contact_instagram'] = esc_url_raw( $_POST['fourbzcore']['contact_instagram'] );
$fourbzcore_cust_fields['contact_tumblr'] = esc_url_raw( $_POST['fourbzcore']['contact_tumblr'] );
$fourbzcore_cust_fields['contact_pinterest'] = esc_url_raw( $_POST['fourbzcore']['contact_pinterest'] );
$fourbzcore_cust_fields['items'] = $_POST['fourbzcore']['items'];
$fourbzcore_cust_fields['avatar'] = esc_url_raw( $_POST['fourbzcore']['avatar'] );
$fourbzcore_cust_fields['avatar_width'] = absint( $_POST['fourbzcore']['avatar_width'] );
$fourbzcore_cust_fields['avatar_height'] = absint( $_POST['fourbzcore']['avatar_height'] );
$fourbzcore_cust_fields['avatar_alt'] = sanitize_text_field( $_POST['fourbzcore']['avatar_alt'] );
update_user_meta( $user_id, $this->db_options_name, $fourbzcore_cust_fields );
}
/**
* 2.3.7 Admin Ajax
*-----------------------------------------------------------------------*/
/**
* Serves an ajax request to show the shortcode builder.
*
* @since 1.0.0
*
* @return string json encoded options.
*/
public function display_shortcode_builder() {
if ( ! wp_verify_nonce( $_REQUEST['nonce'], $this->plugin_prefix . "-shortcode-builder-nonce" ) ) {
exit( __( "No Swiping", $this->txt_domain ) );
}
$result = array();
ob_start();
$this->shortcode_options();
$result['shortcode_builder'] = ob_get_clean();
echo json_encode( $result );
die();
}
/**
* Admin ajax error function
*
* @since 1.0.0
*/
public function no_go() {
echo __( "No Swiping", $this->txt_domain );
die();
}
/**
* 2.4 Front End Methods
*-----------------------------------------------------------------------*/
/**
* Enqueue all required scripts and styles for the front end
*
* @since 1.0.0
*/
public function enqueue_scripts() {
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery-ui-core' );
// Enqueue flexslider js
wp_enqueue_script( 'flexslider', $this->plugin_url . 'js/jquery.flexslider-min.js', array( 'jquery' ), false, true );
// Enqueue flexslider style
wp_enqueue_style( 'flexslider', $this->plugin_url . 'css/flexslider.css' );
// Enqueue font awesome style
wp_enqueue_style( 'font-awesome', $this->plugin_url . 'font-awesome/css/font-awesome.min.css' );
wp_enqueue_script( $this->plugin_prefix . 'frontend', $this->plugin_url . 'js/front-end.js', array( 'jquery' ), false, true );
// Enqueue plugin's style
wp_enqueue_style( $this->plugin_prefix . '-main', $this->plugin_url . 'css/style.css' );
}
/**
* Construct and display scripts and html necessary for social widgets like facebook comments.
*
* Requires app id for facebook, if not provided will not output the scripts and html.
*
* @since 1.0.0
*/
public function output_social_scripts() {
$options = get_option( $this->db_options_name );
$facebook_id = '';
if ( isset( $options['facebook_app_id'] ) ) {
$facebook_id = $options['facebook_app_id'];
}
if ( $facebook_id ) {
echo '
';
}
}
/**
* Get the post meta
*
* @since 1.0.0
*
* @param object $post_id Post id Optional. The id of the post of which to get its post meta. If not provided, will try to retrieve it using the $wp_query variable, if that fails, then return.
*/
public function get_post_meta( $post_id ) {
if ( ! isset( $post_id ) ) {
global $wp_query;
$post_id = $wp_query->post->ID;
}
if ( 'null' === $post_id ) {
return;
}
return get_post_meta( $post_id, $this->db_options_name, true );
}
/**
* Get the user meta
*
* @since 1.0.0
*
* @param object $user_id User id Optional. The id of the user. If not provided, will try to retrieve it using the $wp_query variable, if that fails, then return.
*/
public function get_user_meta( $user_id ) {
if ( ! isset( $user_id ) ) {
global $wp_query;
$user_id = $wp_query->post->post_author;
}
if ( 'null' === $user_id ) {
return;
}
return get_user_meta( $user_id, $this->db_options_name, true );
}
} //End of Class
} //End of if ! class_exists.
// Run the plugin.
$fourbzcore_plugin = new FourBzCore();