plugin_url = plugins_url( basename( dirname( __FILE__ ) ) ); $this->plugin_dir = dirname( __FILE__ ); $this->options = get_option('append_link_on_copy_options'); add_action( 'init', array( &$this, 'init') ); add_action( 'wp', array( &$this, 'load_script' ) ); add_action( 'admin_menu', array( &$this, 'admin_menu' ) ); add_action( 'admin_init', array( &$this, 'admin_init' ) ); } function init(){ $options = get_option( 'append_link_on_copy_options' ); if( !isset($options['readmore']) ) $options['readmore'] = 'Read more at: %link%'; if( !isset($options['prepend_break']) ) $options['prepend_break'] = 2; if( !isset($options['use_title']) ) $options['use_title'] = 'false'; if( !isset($options['add_site_name']) ) $options['add_site_name'] = 'true'; if( !isset($options['always_link_site']) ) $options['always_link_site'] = 'false'; $this->options = $options; } function load_script() { wp_register_script( 'append_link', $this->plugin_url . '/js/append_link.js'); wp_enqueue_script( 'append_link' ); global $post; /* debugging echo '
';
		var_dump( $post );
		echo '
'; */ $options = $this->options; $params = array( 'read_more' => $options['readmore'] , 'prepend_break' => $options['prepend_break'] , 'use_title' => $options['use_title'] , 'add_site_name' => $options['add_site_name'] , 'site_name' => get_bloginfo('name') , 'site_url' => get_bloginfo('url') , 'always_link_site' => $options['always_link_site'] ); if ($options['use_title'] === 'true') { if (is_singular()){ $params['page_title'] = get_the_title($post->ID); } if (is_home() || is_front_page()){ $params['page_title'] = get_bloginfo('name'); $params['add_site_name'] = 'false'; } } wp_localize_script( 'append_link', 'append_link', $params ); } function admin_menu() { // add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function); add_options_page( __( 'Append Link on Copy Options', 'append_link_on_copy' ) , __( 'Append Link on Copy', 'append_link_on_copy' ) , 'manage_options' , 'append_link_on_copy_options' , array(&$this, 'settings_page') ); } function admin_init() { // register_setting( $option_group, $option_name, $sanitize_callback ); register_setting( 'append_link_on_copy_options' , 'append_link_on_copy_options' , array( &$this, 'settings_validate' ) ); // add_settings_section( $id, $title, $callback, $page ); add_settings_section( 'main' , 'Main Settings' , array( &$this, 'section_main' ) , 'append_link_on_copy_options' ); add_settings_section( 'preview' , 'Preview Area' , array( &$this, 'section_preview' ) , 'append_link_on_copy_options' ); // add_settings_field( $id, $title, $callback, $page, $section, $args ); add_settings_field( 'readmore' , "Read more link: (like: Text copied from %link% )" , array( &$this, 'field_readmore' ) , 'append_link_on_copy_options' , 'main' ); add_settings_field( 'add_site_name' , "Add the site name after link" , array( &$this, 'field_add_site_name' ) , 'append_link_on_copy_options' , 'main' ); add_settings_field( 'use_title' , "Use the post title in the paste" , array( &$this, 'field_use_title' ) , 'append_link_on_copy_options' , 'main' ); add_settings_field( 'always_link_site' , "Always link to main site, instead of page/post" , array( &$this, 'field_always_link_site' ) , 'append_link_on_copy_options' , 'main' ); add_settings_field( 'prepend_break' , "How many <br /> tags should be inserted before the link? (default: 2)" , array( &$this, 'field_prepend_break' ) , 'append_link_on_copy_options' , 'main' ); } function section_main() { echo __('Change the appearance and contents of the appended link.'); } function section_preview() { echo 'Notice: Even though the text preview may not show the link, many web systems automatically link everything starting with http://, also everything copied from the front page, will not append the site title'; $sample_quote = "Hi, I'm Jonathan M. Hethey and very happy to provide you with this plugin."; $sample_page_link = 'http://jonathanmh.com/wordpress-plugin-append-link-on-copy/'; $sample_site_link = 'http://jonathanmh.com/'; $sample_site_name = 'JonathanMH.com'; if ($this->options['always_link_site'] == true) { $link = ''; } else { $link = ''; } if ($this->options['use_title'] == 'true'){ $link .= 'Append Link on Copy'; } else { if ($this->options['always_link_site'] == true){ $link .= $sample_site_link; } else { $link .= $sample_page_link; } } if ($this->options['add_site_name'] == 'true'){ $link .= ' | ' . $sample_site_name; } $link .= ''; echo '

' . 'Quoted text:

'; echo "
"; echo $sample_quote; echo "
"; echo '

sample page link: ' . $sample_page_link . '

'; echo '

sample site link: ' . $sample_site_link . '

'; echo '

sample site name: ' . $sample_site_name . '

'; echo '

' . 'HTML preview' . '

'; echo "
"; echo $sample_quote; for ($i = 0; $i < $this->options['prepend_break']; $i++){ echo '
'; } echo $this->options['readmore'] . ' ' . $link; echo "
"; echo '

' . 'Text preview' . '

'; echo "
"; echo strip_tags($sample_quote); for ($i = 0; $i < $this->options['prepend_break']; $i++){ echo '
'; } echo $this->options['readmore'] . ' ' . strip_tags($link); echo "
"; } function field_readmore() { echo ''; } function field_prepend_break() { echo ''; } function field_add_site_name() { echo '' . '