version = '1.1.0'; $this->register_styles_and_scripts(); $this->add_new_shortcode( 'row', 'row_shortcode_callback' ); $this->add_new_shortcode( 'span', 'span_shortcode_callback' ); add_action('init', array(self::$instance, 'wp1180px_shortcode_button_init')); } /** * Register CSS and JavaScript files */ private function register_styles_and_scripts() { add_action( 'wp_enqueue_scripts', array(self::$instance, 'register_1180_css_file') ); } /** * Registers the 1180px css file */ public function register_1180_css_file() { wp_enqueue_style( '1180px', plugins_url( '/css/1180px.css', __FILE__ ), array(), $this->get_version(), 'all' ); } /** * Registers the shortcode with @WordPress */ private function add_new_shortcode($shortcode, $callback) { add_shortcode( $shortcode, array(self::$instance, $callback) ); } /** * Callback function to specify the output * of the [row] shortcode * * @param array $atts * @param array $content * * @return string */ public function row_shortcode_callback( $atts, $content = null ) { $content = $this->sanitizeContent($content); if(isset($atts['class'])) { return '
' . $content . '
'; } return '
' . $content . '
'; } /** * Callback function for the registered span shortcodes * * @param array $atts * @param null $content * @param string $tag * * @return string */ public function span_shortcode_callback($atts, $content = null) { $content = $this->sanitizeContent($content); return '
' . $content . '
'; } /** * Create a new button on the WYSIWYG editor * for the row and span shortcodes */ public function wp1180px_shortcode_button_init() { // Abort early if the user will never see TinyMCE if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') && get_user_option('rich_editing') == 'true') return; //Add a callback to regiser our tinymce plugin add_filter('mce_external_plugins', array(self::$instance, 'wp1180px_register_tinymce_plugin') ); // Add a callback to add our button to the TinyMCE toolbar add_filter('mce_buttons', array(self::$instance, 'wp1180p_add_tinymce_button') ); } /** * Register a new tinymce plugin * * @param array $plugin_array * @return array */ public function wp1180px_register_tinymce_plugin($plugin_array) { $plugin_array['wp1180px_buttons'] = plugin_dir_url(__FILE__) . '/js/1180px_tinymce_plugin.js'; return $plugin_array; } /** * Add new tinymce buttons to the editor * * @param array $buttons * @return array */ public function wp1180p_add_tinymce_button($buttons) { array_push( $buttons, 'wp1180px_row', 'wp1180px_span' ); return $buttons; } /** * Remove excess whitespace from shortcode content * and return the $content * * @param mixed|string $content * @return mixed|string $content */ public function sanitizeContent($content) { /* Parse nested shortcodes and add formatting. */ $content = trim( do_shortcode( shortcode_unautop( $content ) ) ); /* Remove '' from the start of the string. */ if ( substr( $content, 0, 4 ) == '' ) $content = substr( $content, 4 ); /* Remove '' from the end of the string. */ if ( substr( $content, -3, 3 ) == '' ) $content = substr( $content, 0, -3 ); /* Remove any instances of ''. */ $content = str_replace( array( '

' ), '', $content ); $content = str_replace( array( '

' ), '', $content ); remove_filter( 'the_content', 'wpautop' ); add_filter( 'the_content', 'wpautop' , 99); add_filter( 'the_content', 'shortcode_unautop',100 ); return $content; } /** * Get the version number for the plugin * * @return string */ public function get_version() { return $this->version; } } ElevenEightyShortcodes::init();