post_type && $pagenow == 'post-new.php' || $pagenow == 'post.php' ) : $post_type = $post->post_type; wp_register_script( 'ayo_actionjs2', AdminYo_dirURL . '../js/ayo_holdactionbtn.js' ); wp_enqueue_script( 'ayo_actionjs2', AdminYo_dirURL . '../js/ayo_holdactionbtn.js', array( 'jquery' ) ); //CSS Styles if ($ayo_options['hold_clickfab'] == true) { wp_register_style( 'ayo_holdclick', AdminYo_dirURL . '../css/ayo_circular_plus.css' ); wp_enqueue_style('ayo_holdclick'); }; else : return false; endif; return $post_type; //second } public function ayo_register_admin_styles() { /* Only load js css we are are editing a post (build in or custom post type) or page*/ if($this->x_get_current_post_type()) : endif; } public function ayo_register_admin_scripts() { /* Only load js if we are are editing a post (build in or custom post type) or page*/ if($this->x_get_current_post_type()) : /// function enqueue_scripts_styles_init() { wp_enqueue_script( 'ajax-script', plugins_url( '/js/ayo_pin.js', __FILE__ ), array('jquery'), 1.0 ); // jQuery will be included automatically wp_localize_script( 'ajax-script', 'ajax_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); // setting ajaxurl // wp_enqueue_script( 'ajax-script', plugins_url( '/js/ayo_actionbtn.js', __FILE__ ), array('jquery'), 1.0 ); }; add_action('init', 'enqueue_scripts_styles_init'); function publish_post() { wp_localize_script('updatefrombottom-admin-script', 'updatefrombottomParams', 'update'); }; // add_action('post_submitbox_misc_actions', 'pin_the_post'); function ayo_pin_the_post(){ $cote = get_post_meta($_POST['id'], 'pin_featured', true); if($_POST['pin_featured'] == 'no') { // $newCote = $cote++; update_post_meta($_POST['id'], 'pin_featured', 'yes'); } else { // $newCote = $cote--; update_post_meta($_POST['id'], 'pin_featured', 'no'); } }; add_action('the_action_hook', 'ayo_pin_the_post'); /* Button Render */ global $ayo_options; if ($ayo_options['menu_post_plus'] == true) { ?>
post_author; */ $current_user = wp_get_current_user(); $new_post_author = $current_user->ID; /* if post data exists, create the post duplicate */ if (isset( $post ) && $post != null) { /* new post data array*/ $args = array( 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'post_author' => $new_post_author, 'post_content' => $post->post_content, 'post_excerpt' => $post->post_excerpt, 'post_name' => $post->post_name.'_copy', 'post_parent' => $post->post_parent, 'post_password' => $post->post_password, 'post_status' => 'draft', 'post_title' => $post->post_title.'_copy', 'post_type' => $post->post_type, 'to_ping' => $post->to_ping, 'menu_order' => $post->menu_order ); /* insert the post by wp_insert_post() function */ $new_post_id = wp_insert_post( $args ); /* get all current post terms ad set them to the new post draft */ $taxonomies = get_object_taxonomies($post->post_type); // returns array of taxonomy names for post type, ex array("category", "post_tag"); foreach ($taxonomies as $taxonomy) { $post_terms = wp_get_object_terms($post_id, $taxonomy, array('fields' => 'slugs')); wp_set_object_terms($new_post_id, $post_terms, $taxonomy, false); } /* duplicate all post meta just in two SQL queries */ $post_meta_infos = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id"); if (count($post_meta_infos)!=0) { $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) "; foreach ($post_meta_infos as $meta_info) { $meta_key = $meta_info->meta_key; $meta_value = addslashes($meta_info->meta_value); $sql_query_sel[]= "SELECT $new_post_id, '$meta_key', '$meta_value'"; } $sql_query.= implode(" UNION ALL ", $sql_query_sel); $wpdb->query($sql_query); } /* finally, redirect to the edit post screen for the new draft */ wp_redirect( admin_url( 'post.php?action=edit&post=' . $new_post_id ) ); exit; } else { wp_die('Post creation failed, could not find original post: ' . $post_id); } } add_action( 'admin_action_ayo_duplicate_post_as_draft', 'ayo_duplicate_post_as_draft' ); /* Function creates post duplicate as a publish and redirects then to the edit post screen */ function ayo_duplicate_post_as_publish(){ global $wpdb; if (! ( isset( $_GET['post']) || isset( $_POST['post']) || ( isset($_REQUEST['action']) && 'ayo_duplicate_post_as_publish' == $_REQUEST['action'] ) ) ) { wp_die('No post to duplicate has been supplied!'); } /* get the original post id */ $post_id = (isset($_GET['post']) ? absint( $_GET['post'] ) : absint( $_POST['post'] ) ); /* and all the original post data then */ $post = get_post( $post_id ); /* if you don't want current user to be the new post author, then change next couple of lines to this: $new_post_author = $post->post_author; */ $current_user = wp_get_current_user(); $new_post_author = $current_user->ID; /* if post data exists, create the post duplicate */ if (isset( $post ) && $post != null) { /* new post data array */ $args = array( 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'post_author' => $new_post_author, 'post_content' => $post->post_content, 'post_excerpt' => $post->post_excerpt, 'post_name' => $post->post_name.'_copy', 'post_parent' => $post->post_parent, 'post_password' => $post->post_password, 'post_status' => 'draft', 'post_title' => $post->post_title.'_copy', 'post_type' => $post->post_type, 'to_ping' => $post->to_ping, 'menu_order' => $post->menu_order ); /* insert the post by wp_insert_post() function */ $new_post_id = wp_insert_post( $args ); /* get all current post terms ad set them to the new post draft */ $taxonomies = get_object_taxonomies($post->post_type); // returns array of taxonomy names for post type, ex array("category", "post_tag"); foreach ($taxonomies as $taxonomy) { $post_terms = wp_get_object_terms($post_id, $taxonomy, array('fields' => 'slugs')); wp_set_object_terms($new_post_id, $post_terms, $taxonomy, false); } /* duplicate all post meta just in two SQL queries */ $post_meta_infos = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->postmeta WHERE post_id=$post_id"); if (count($post_meta_infos)!=0) { $sql_query = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) "; foreach ($post_meta_infos as $meta_info) { $meta_key = $meta_info->meta_key; $meta_value = addslashes($meta_info->meta_value); $sql_query_sel[]= "SELECT $new_post_id, '$meta_key', '$meta_value'"; } $sql_query.= implode(" UNION ALL ", $sql_query_sel); $wpdb->query($sql_query); } //echo $post->post_type; die; /* finally, redirect to the edit post screen for the new publish */ wp_redirect( admin_url( 'edit.php?post_type=' . $post->post_type ) ); exit; } else { wp_die('Post creation failed, could not find original post: ' . $post_id); } } add_action( 'admin_action_ayo_duplicate_post_as_publish', 'ayo_duplicate_post_as_publish' ); /* Add the duplicate link to action list for post_row_actions */ function ayo_duplicate_post_link( $actions, $post ) { if (current_user_can('edit_posts')) { $actions['duplicate'] = 'Duplicate & Edit'; $actions['clone'] = 'Duplicate'; } return $actions; } add_filter( 'post_row_actions', 'ayo_duplicate_post_link', 10, 2 ); add_filter('page_row_actions', 'ayo_duplicate_post_link', 10, 2); /* Only use in wp-admin*/ if (is_admin()): $ufb = new Ayo_Action_Button(); endif; /* Card unPin */ add_action( 'wp_ajax_ayo_actionbtn_pin', 'ayo_actionbtn_pin' ); function ayo_actionbtn_pin() { $meta = get_post_meta( $_GET["post_id"], '_is_featured', true ); if (strlen($meta) == 0 ) { update_post_meta($_GET["post_id"], '_is_featured', 'yes'); header("Location: ".$_SERVER['PHP_SELF']); } else { delete_post_meta($_GET["post_id"], '_is_featured', 'yes'); // header("Refresh:0"); header("Location: ".$_SERVER['PHP_SELF']); } echo $_GET["post_id"]; die(); } //END of file