__construct();} /** * PHP 5 Constructor */ function __construct(){ //"Constants" setup $this->thispluginurl = WP_PLUGIN_URL . '/' . dirname(plugin_basename(__FILE__)).'/'; $this->thispluginpath = WP_PLUGIN_DIR . '/' . dirname(plugin_basename(__FILE__)).'/'; //fillUsers array for use in the dropdown add_action('init', array(&$this,"fillUsers"), 0); //Menu for Media Categories Options Admin section add_action("admin_menu", array(&$this,"admin_menu_link"), 0); //Initialize the options $this->getOptions(); /* Define the custom box */ add_action( 'add_meta_boxes', array(&$this,'autp_add_custom_box') ); /* Do something with the data entered */ add_action( 'save_post', array(&$this,'autp_save_postdata') ); /* AJAX for adding users */ add_action('admin_head', array(&$this,'adduser_autp_action_javascript')); add_action('wp_ajax_adduser_autp_action', array(&$this,'adduser_autp_action_callback')); } function fillUsers() { $args = array( 'blog_id' => $GLOBALS['blog_id'], 'orderby' => 'display_name', 'order' => 'ASC', 'count_total' => true, 'fields' => 'all' ); autp::$allUsers = get_users($args); } function getOptions() { if (!$theOptions = get_option(self::$optionsName)) { $theOptions = array('default'=>'options'); update_option(self::$optionsName, $theOptions); } $this->options = $theOptions; if (!isset($this->options['autp_posttypes'])) { $defaultValues= array(); array_push($defaultValues, 'post'); array_push($defaultValues, 'page'); $this->options['autp_posttypes']=$defaultValues; } } /* Adds a box to the main column on the Post and Page edit screens */ function autp_add_custom_box() { //global $pagenow, $post; if (current_user_can(self::$adminCapability)) { $autp_posttypes = isset($this->options['autp_posttypes'])?:null; if ($autp_posttypes == null || !is_array($autp_posttypes)) { foreach($this->options['autp_posttypes'] as $posttype) { add_meta_box( 'autp_sectionid', __( 'Users', 'autp_textdomain' ), array( &$this, 'autp_inner_custom_box' ), $posttype, 'normal', 'high' ); } } } } /* Prints the box content */ function autp_inner_custom_box( $post ) { global $autp_dir, $autp_base; // Use nonce for verification wp_nonce_field( plugin_basename( __FILE__ ), 'autp_noncename' ); echo " "; echo "
Add User
"; echo ""; echo ""; echo ""; } /* When the post is saved, saves our custom data */ function autp_save_postdata( $post_id ) { // verify if this is an auto save routine. // If it is our form has not been submitted, so we dont want to do anything if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if (isset($_POST['autp_noncename']) && !wp_verify_nonce( $_POST['autp_noncename'], plugin_basename( __FILE__ ) ) ) return; // Check permissions if ( 'page' == $_POST['post_type'] ) { if ( !current_user_can( 'edit_page', $post_id ) ) return; } else { if ( !current_user_can( 'edit_post', $post_id ) ) return; } // OK, we're authenticated: we need to find and save the data $i=1; $newvalue = array(); if(isset($_POST['currentuser_updatedsort'])) { $currentsort = $this->_unserializeJQuery($_POST['currentuser_updatedsort']); if(!empty($currentsort)) { $count_total = count($currentsort); for($i = 0; $i <$count_total; ++$i) { $id=$currentsort[$i]; $array = array(); $array['user_id'] = $_POST['currentuser_'.$id.'_id']; $array['user_title'] = $_POST['currentuser_'.$id.'_title']; $array['user_info'] = $_POST['currentuser_'.$id.'_info']; $array['user_showinfo'] = isset($_POST['currentuser_'.$id.'_show'])?true:false; $array['user_sortorder'] = $i; $newvalue[] = $array; } } } add_post_meta($post_id, 'autp', $newvalue, true) or update_post_meta($post_id, 'autp', $newvalue); } function adduser_autp_action_javascript() { ?> user_description; $html = $this->GetLI($i, $id, $info); echo $html; } die(); // this is required to return a proper result } function GetLI($fieldId, $user_id, $info) { $user_info = get_userdata($user_id); $image = get_avatar( $user_id, 60 ); $html = "
  • $user_info->first_name $user_info->last_name : $user_info->user_nicename

    Delete User
    $image

    Email: $user_info->user_email

     
  • "; return $html; } //Place Options Link In Left Nav function admin_menu_link() { add_options_page('Add User Options', 'Add User Options', self::$optionsMenuCapability, basename(__FILE__), array(&$this,'admin_options_page')); add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array(&$this, 'filter_plugin_actions'), self::$optionsMenuCapability, 2 ); } //Place settings link on plugin page function filter_plugin_actions($links, $file) { $settings_link = '' . __('Settings') . ''; array_unshift( $links, $settings_link ); // before other links return $links; } function saveAdminOptions(){ return update_option(self::$optionsName, $this->options); } function admin_options_page() { global $autp_dir, $autp_base; global $wp_roles; if(isset($_POST['autp_save']) && $_POST['autp_save']){ if (! wp_verify_nonce($_POST['_wpnonce'], 'autp-update-options') ) die('Whoops! There was a problem with the data you posted. Please go back and try again.'); //SAVE OPTIONS $autp_posttypes = @$_POST['autp_posttypes'] ; if ($autp_posttypes !== null && is_array($autp_posttypes)) { $this->options['autp_posttypes'] =$autp_posttypes; } $this->saveAdminOptions(); //SAVE ROLES $adminRoles = @$_POST['autp_adminRoles'] ; $assignRoles = @$_POST['autp_assignRoles']; foreach ($wp_roles->get_names() as $role_name => $formal_name ) { $role = get_role( $role_name ) ; if ($adminRoles !== null && is_array($adminRoles) && in_array($role_name, $adminRoles)) { $role->add_cap( autp::$adminCapability ) ; } else { $role->remove_cap( autp::$adminCapability ); } if ($assignRoles !== null && is_array($assignRoles) && in_array($role_name, $assignRoles)) { $role->add_cap( autp::$assignCapability ) ; } else { $role->remove_cap( autp::$assignCapability ); } } echo '

    Success! Your changes were sucessfully saved!

    '; } //post types for multiselect $post_types = get_post_types(array('public' => true)); foreach($post_types as $key => $value) { if($value == 'attachment') { unset($post_types[$key]); } } ?>

    Options - Add Users To PostType

    ID, 'autp'); if(!empty($CurrentUsers)) { foreach($CurrentUsers as $cu) { foreach($cu as $value) { $id= $value['user_id']; $info= $value['user_info']; $image = get_avatar( $id, 60 ); $user_info = get_userdata($id); if($info=='') $info = $user_info->user_description; echo "

    $user_info->first_name $user_info->last_name

    $image

    Email: $user_info->user_email

    $info

    "; } } } } } /* ============================ * MISC FUNCTIONS * ============================ */ function _unserializeJQuery($rubble = NULL) { $bricks = explode('&', $rubble); $built= array(); foreach ($bricks as $key => $value) { $walls = preg_split('/=/', $value); $value = urldecode($walls[1]); array_push($built, ((int)$value)); } return $built; } function contains($mystring, $findme) { $pos = strpos($mystring, $findme); if($pos === false) { // string needle NOT found in haystack return false; } else { // string needle found in haystack return true; } } function cleanQuery($string) { if(get_magic_quotes_gpc()) // prevents duplicate backslashes { $string = stripslashes($string); } if (phpversion() >= '4.3.0') { $string = mysql_real_escape_string($string); } else { $string = mysql_escape_string($string); } return $string; } /* ============================ * Activation * ============================ */ static function autp_plugin_activate() { // Initialize default capabilities $role = get_role( 'administrator' ); $role->add_cap( self::$adminCapability ); $role->add_cap( self::$assignCapability ); $role = get_role( 'editor' ); $role->add_cap( self::$adminCapability ); $role->add_cap( self::$assignCapability ); $role = get_role( 'author' ); $role->add_cap( self::$assignCapability ); } /* ============================ * UNINTALL * ============================ */ static function autp_plugin_uninstall() { global $wp_roles; // Initialize default capabilities $rolenames = $wp_roles->get_names() ; foreach ( $rolenames as $rolename => $displ ) { $role = get_role( $rolename ); $role->remove_cap( self::$adminCapability ); $role->remove_cap( self::$assignCapability ); } delete_option(self::$optionsName); } } //End Class } //End if class exists statement //instantiate the class if (class_exists('autp')) { $autp_var = new autp(); } ?>