apss_settings = get_option( APSS_SETTING_NAME ); //get the plugin variable contents from the options table. register_activation_hook( __FILE__, array( $this, 'plugin_activation' ) ); //load the default setting for the plugin while activating add_action( 'init', array( $this, 'plugin_text_domain' ) ); //load the plugin text domain add_action( 'init', array( $this, 'session_init' ) ); //start the session if not started yet. add_action( 'admin_enqueue_scripts', array( $this, 'register_admin_assets' ) ); //registers all the assets required for wp-admin add_filter( 'the_content', array( $this, 'apss_the_content_filter' ), 12 ); // add the filter function for display of social share icons in frontend //added 12 priority level at the end to make the plugin compactible with Visual Composer. if ( isset( $this->apss_settings['disable_frontend_assets'] ) && $this->apss_settings['disable_frontend_assets'] != '1' ) { add_action( 'wp_enqueue_scripts', array( $this, 'register_frontend_assets' ) ); //registers all the assets required for the frontend } else if ( !isset( $this->apss_settings['disable_frontend_assets'] ) ) { add_action( 'wp_enqueue_scripts', array( $this, 'register_frontend_assets' ) ); //registers all the assets required for the frontend } add_action( 'admin_menu', array( $this, 'add_apss_menu' ) ); //register the plugin menu in backend add_action( 'admin_post_apss_save_options', array( $this, 'apss_save_options' ) ); //save the options in the wordpress options table. add_action( 'admin_post_apss_restore_default_settings', array( $this, 'apss_restore_default_settings' ) ); //restores default settings. add_action( 'admin_post_apss_clear_cache', array( $this, 'apss_clear_cache' ) ); //clear the cache of the social share counter. add_shortcode( 'apss-share', array( $this, 'apss_shortcode' ) ); //adds a shortcode add_shortcode( 'apss_share', array( $this, 'apss_shortcode' ) ); //added a new shortcode to remove the shortcode with hyphen in future add_shortcode( 'apss-count', array( $this, 'apss_count_shortcode' ) ); //adds a share count shortcode add_shortcode( 'apss_count', array( $this, 'apss_count_shortcode' ) ); //added a new shortcode to remove the shortcode with hyphen in future add_action( 'add_meta_boxes', array( $this, 'social_meta_box' ) ); //for providing the option to disable the social share option in each frontend page add_action( 'save_post', array( $this, 'save_meta_values' ) ); //function to save the post meta values of a plugin. add_action( 'wp_ajax_nopriv_frontend_counter', array( $this, 'frontend_counter' ) ); //fetching of the social share count. add_action( 'wp_ajax_frontend_counter', array( $this, 'frontend_counter' ) ); // action for ajax counter. } //called when plugin is activated function plugin_activation() { if ( !get_option( APSS_SETTING_NAME ) ) { include( 'inc/backend/activation.php' ); } if ( !get_option( APSS_COUNT_TRANSIENTS ) ) { $apss_social_counts_transients = array(); update_option( APSS_COUNT_TRANSIENTS, $apss_social_counts_transients ); } } //loads the text domain for translation function plugin_text_domain() { load_plugin_textdomain( 'accesspress-social-share', false, APSS_LANG_DIR ); } //starts the session with the call of init hook function session_init() { if ( !session_id() && !headers_sent() ) { session_start(); } } //functions to register frontend styles and scripts function register_admin_assets() { /** * Backend CSS * */ if ( isset( $_GET['page'] ) && $_GET['page'] == 'accesspress-social-share' ) { wp_enqueue_style( 'aps-admin-css', APSS_CSS_DIR . '/backend.css', false, APSS_VERSION ); //registering plugin admin css wp_enqueue_style( 'fontawesome-css', '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css', false, APSS_VERSION ); /** * Backend JS * */ wp_enqueue_script( 'jquery-ui-sortable' ); wp_enqueue_script( 'apss-admin-js', APSS_JS_DIR . '/backend.js', array( 'jquery', 'jquery-ui-sortable', 'wp-color-picker' ), APSS_VERSION ); //registering plugin's admin js } } //function to return the content filter for the posts and pages function apss_the_content_filter( $content ) { if(in_array('get_the_excerpt', $GLOBALS['wp_current_filter'])) return $content; global $post; $post_content = $content; $title = str_replace( '+', '%20', urlencode( $post->post_title ) ); $content = strip_shortcodes( strip_tags( get_the_content() ) ); if ( strlen( $content ) >= 100 ) { $excerpt = substr( $content, 0, 100 ) . '...'; } else { $excerpt = $content; } $options = $this->apss_settings; ob_start(); include('inc/frontend/content-filter.php'); $html_content = ob_get_contents(); ob_get_clean(); $share_shows_in_options = $options['share_options']; $content_flag = get_post_meta( $post->ID, 'apss_content_flag', true ); $all = in_array( 'all', $options['share_options'] ); $is_lists_authorized = (is_search() && $content_flag != '1' ) && $all ? true : false; $is_attachement_check = in_array( 'attachment', $options['share_options'] ); $is_attachement = (is_attachment() && $is_attachement_check ) ? true : false; $front_page = in_array( 'front_page', $options['share_options'] ); $is_front_page = (is_front_page() && $content_flag != '1' ) && $front_page ? true : false; $share_shows_in_options = $options['share_options']; $is_singular = is_singular( $share_shows_in_options ) && !is_front_page() && $content_flag != '1' ? true : false; if ( !empty( $share_shows_in_options ) ) { $is_tax = is_tax( $share_shows_in_options ); } else { $is_tax = false; } $is_category = in_array( 'categories', $options['share_options'] ); $default_category = ( is_category() ) && $is_category ? true : false; $is_default_archive = in_array( 'archives', $options['share_options'] ); $default_archives = ( ( is_archive() && !is_tax() ) && !is_category() ) && $is_default_archive ? true : false; if ( empty( $options['share_options'] ) ) { return $post_content; } else if ( $is_lists_authorized || $is_attachement || $is_singular || $is_tax || $is_front_page || $default_category || $default_archives ) { if ( $options['share_positions'] == 'below_content' ) { return $post_content . "
"; } if ( $options['share_positions'] == 'above_content' ) { return "" . $post_content; } if ( $options['share_positions'] == 'on_both' ) { return "" . $post_content . ""; } } else { return $post_content; } } /** * Registers Frontend Assets * */ function register_frontend_assets() { wp_enqueue_style( 'apss-font-awesome', '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css', array(), APSS_VERSION ); wp_enqueue_style( 'apss-font-opensans', '//fonts.googleapis.com/css?family=Open+Sans', array(), false ); wp_enqueue_style( 'apss-frontend-css', APSS_CSS_DIR . '/frontend.css', array( 'apss-font-awesome' ), APSS_VERSION ); wp_enqueue_script( 'apss-frontend-mainjs', APSS_JS_DIR . '/frontend.js', array( 'jquery' ), APSS_VERSION, true ); $ajax_nonce = wp_create_nonce( 'apss-ajax-nonce' ); wp_localize_script( 'apss-frontend-mainjs', 'frontend_ajax_object', array( 'ajax_url' => admin_url() . 'admin-ajax.php', 'ajax_nonce' => $ajax_nonce ) ); } //add plugins menu in backend function add_apss_menu() { add_menu_page( 'AccessPress Social Share', 'AccessPress Social Share', 'manage_options', 'accesspress-social-share', array( $this, 'main_page' ), APSS_IMAGE_DIR . '/apss-icon.png' ); //add_submenu_page( 'accesspress-social-share', __( 'SAccessPress Social Share', 'accesspress-social-share' ), __( 'Social Icons Settings', 'accesspress-social-share' ), 'manage_options', 'accesspress-social-share', array( $this, 'main_page' ) ); } //for saving the plugin settings function apss_save_options() { if ( isset( $_POST['apss_add_nonce_save_settings'] ) && isset( $_POST['apss_submit_settings'] ) && wp_verify_nonce( $_POST['apss_add_nonce_save_settings'], 'apss_nonce_save_settings' ) ) { include( 'inc/backend/save-settings.php' ); } else { die( 'No script kiddies please!' ); } } //function to restore the default setting of a plugin function apss_restore_default_settings() { $nonce = $_REQUEST['_wpnonce']; if ( !empty( $_GET ) && wp_verify_nonce( $nonce, 'apss-restore-default-settings-nonce' ) ) { //restore the default plugin activation settings from the activation page. include( 'inc/backend/activation.php' ); $_SESSION['apss_message'] = __( 'Settings restored Successfully.', 'accesspress-social-share' ); wp_redirect( admin_url() . 'admin.php?page=accesspress-social-share' ); exit; } else { die( 'No script kiddies please!' ); } } /** * Clears the social share counter cache */ function apss_clear_cache() { if ( !empty( $_GET ) && wp_verify_nonce( $_GET['_wpnonce'], 'apss-clear-cache-nonce' ) ) { $apss_settings = $this->apss_settings; $apss_social_counts_transients = get_option( APSS_COUNT_TRANSIENTS ); foreach ( $apss_social_counts_transients as $transient ) { delete_transient( $transient ); } update_option( APSS_COUNT_TRANSIENTS, array() ); $transient_array = array( 'apss_tweets_count', 'apss_linkedin_count', 'apss_fb_count', 'apss_pin_count', 'apss_google_plus_count' ); foreach ( $transient_array as $transient ) { delete_transient( $transient ); } $_SESSION['apss_message'] = __( 'Cache cleared Successfully', 'accesspress-social-share' ); wp_redirect( admin_url() . 'admin.php?page=accesspress-social-share' ); } } //function for adding shortcode of a plugin function apss_shortcode( $attr ) { ob_start(); include( 'inc/frontend/shortcode.php' ); $html = ob_get_contents(); ob_get_clean(); return $html; } //frontend counter function frontend_counter() { if ( !empty( $_GET ) && wp_verify_nonce( $_GET['_wpnonce'], 'apss-ajax-nonce' ) ) { $apss_settings = $this->apss_settings; $new_detail_array = array(); if ( isset( $_POST['data'] ) ) { $details = $_POST['data']; foreach ( $details as $detail ) { $new_detail_array[$detail['network']] = $this->get_count( $detail['network'], $detail['url'] ); } } else if ( isset( $_POST['shortcode_data'] ) ) { $shortcode_data = $_POST['shortcode_data']; foreach ( $shortcode_data as $detail ) { $detail_array = explode( '_', $detail ); $url = trim( $detail_array[0] ); $network = $detail_array[1]; $new_detail_array[] = $this->get_count( $network, $url ); } } die( json_encode( $new_detail_array ) ); } } //frontend counter only Shortcode function apss_count_shortcode( $atts ) { if ( isset( $atts['network'] ) ) { $url = $this->curPageURL(); $count = $this->get_count( $atts['network'], $url ); return $count; } } ///////////////////////////for post meta options////////////////////////////////// /** * Adds a section in all the post and page section to disable the share options in frontend pages */ function social_meta_box() { add_meta_box( 'ap-share-box', 'AccessPress social share options', array( $this, 'metabox_callback' ), '', 'side', 'core' ); } function metabox_callback( $post ) { wp_nonce_field( 'save_meta_values', 'ap_share_meta_nonce' ); $content_flag = get_post_meta( $post->ID, 'apss_content_flag', true ); ?>