settings = get_option( 'atui_settings' );
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'add_plugin_action_links' ) );
add_filter( 'plugin_row_meta', array( $this, 'add_plugin_row_meta' ), 10, 2 );
register_activation_hook( __FILE__, array( $this, 'install_plugin' ) );
if ( $this->settings['number_to_show'] == 'all' ) {
add_filter( 'get_terms_args', array( $this, 'show_all_tags' ) );
}
$current_page = basename( $_SERVER['PHP_SELF'] );
// only run on add/edit post pages.
if ( ( $current_page == 'post.php' || $current_page == 'post-new.php' ) && ( ! isset( $_GET['post_type'] ) || $_GET['post_type'] != 'page' ) )
{
add_action( 'admin_head', array( $this, 'add_style_to_head' ) );
add_action( 'admin_footer-post.php', array( $this, 'add_script_to_footer' ) );
add_action( 'admin_footer-post-new.php', array( $this, 'add_script_to_footer' ) );
}
// only run on settings page
if ( ( $current_page == 'plugins.php' && isset( $_GET['page'] ) && $_GET['page'] == 'atui-page' ) || $current_page == 'options.php' )
{
require_once ( plugin_dir_path( __FILE__ ) . 'admin-tag-ui-settings.php' );
$settings_page = new Admin_Tag_UI_Settings_Page( $this );
}
}
/**
* Removes the limit on the number of tags to show
* - filter get_terms_args - __construct()
* @param $args
* @return mixed
*/
public function show_all_tags( $args )
{
if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_POST['action'] ) && $_POST['action'] === 'get-tagcloud' )
{
unset ( $args['number'] );
$args['hide_empty'] = 0;
}
return $args;
}
/**
* Adds a settings link to the plugin's actions under plugins.php
* - filter plugin_action_links_ . plugin_basename( __FILE__ ) - __construct()
* @param $links
* @return array
*/
public function add_plugin_action_links( $links )
{
$add_links = array();
$add_links[] = 'Settings';
return array_merge( $add_links, $links );
}
/**
* Adds a view more link to the plugin's meta under plugins.php
* - filter plugin_row_meta - __construct()
* @param $links
* @param $file
* @return array
*/
public function add_plugin_row_meta( $links, $file )
{
$plugin = plugin_basename( __FILE__ );
$add_links = array();
if ( $file == $plugin ) {
$add_links[] = 'View more plugins';
}
return array_merge( $links, $add_links );
}
/**
* Disabled now, not sure if this will be used in the future.
* Was running from __construct:
* if ( $this->settings['number_to_show'] == 'all' ) {
* add_filter( 'gettext', array( $this, 'change_show_tags_text'), 1, 3 );
* }
*/
/*public function change_show_tags_text( $translated_text, $text, $domain )
{
if ( 'Choose from the most used tags' == $text ) // && 'your-post-type' == $typenow
{
$translated_text = __( 'Choose from all tags', 'admin-tag-ui' );
}
return $translated_text;
}*/
/**
* Default settings for the plugin. Returns an array if no parameters passed in. Pass in a name to get the default for that setting.
* @param string $setting
* @return array|mixed
*/
public function default_settings( $setting = '' )
{
$default = array(
'number_to_show' => 'all',
'number_of_columns' => 2,
'tag_size' => 'same',
'auto_reveal' => 1,
);
if ( empty( $setting ) )
{
return $default;
}
else
{
return $default[ $setting ];
}
}
/**
* Adds css
HTML;
echo $output;
}
/**
* Adds jquery
HTML;
echo $output;
}
/**
* Adds array of default settings to an option in the wp options table
* - register_activation_hook __FILE__
*/
public function install_plugin()
{
add_option( 'atui_settings', $this->default_settings() );
}
}
if ( is_admin() )
{
$admin_tag_ui_plugin = new Admin_Tag_UI_Plugin();
}