-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adicionando classe de Post Status #310
Changes from 2 commits
6599205
e8f3185
02fb2e0
f566deb
c32369c
a47222b
170b0ca
a2d0608
863bb0f
c2472f1
74fac05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
(function ( $ ) { | ||
'use strict'; | ||
|
||
/** | ||
* Custom post status | ||
*/ | ||
$( window ).load( function() { | ||
$( 'meta.odin-custom-status-meta' ).each( function() { | ||
if( $( document.body ).hasClass( 'post-php' ) || $( document.body ).hasClass( 'post-new-php' ) ) { | ||
console.log('ahoy'); | ||
var select = ''; | ||
if( typeof args.select !== 'undefined' ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -1 if( !args.select ) { |
||
select = 'selected="selected"'; | ||
$( 'label[for="post_status"]').append( '<span id="post-status-display"> ' + $.trim( args.appliedLabel ) + '</span>' ); | ||
} | ||
var html = '<option value="' + $.trim( args.slug ) + '" ' + $.trim( select ) + '>' + $.trim( args.appliedLabel ) + '</option>'; | ||
$( '#post_status' ).append( html ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -1 |
||
} | ||
if( $( document.body ).hasClass( 'edit-php' ) ) { | ||
var args = $.parseJSON( $(this).attr('value') ); | ||
var html = '<option value="' + $.trim( args.slug ) + '">' + $.trim( args.appliedLabel ) + '</option>'; | ||
$( '.inline-edit-status select' ).each(function(){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -1 |
||
$(this).append( html ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -1 |
||
}); | ||
} | ||
}); | ||
}); | ||
}( jQuery )); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -1 |
||
<?php | ||
/** | ||
* Odin_Metabox class. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
<?php | ||
/** | ||
* Odin_Post_Status Class. | ||
* | ||
* Build Custom Post Status | ||
* | ||
* @package Odin | ||
* @category Post Status | ||
* @author WPBrasil | ||
* @version 2.1.4 | ||
**/ | ||
class Odin_Post_Status { | ||
|
||
/** | ||
* The name of Custom Post Status. | ||
* | ||
* @var string | ||
**/ | ||
protected $post_status; | ||
|
||
/** | ||
* Array of Post Types will applied to. | ||
* | ||
* @var arrays | ||
**/ | ||
protected $post_types = array(); | ||
|
||
/** | ||
* Text used to display the custom post status | ||
* when it can be applied to a post. | ||
* | ||
* @var string | ||
**/ | ||
protected $action_label; | ||
|
||
/** | ||
* Text used to display the custom post status | ||
* when it has been applied to a post. | ||
* | ||
* @var string | ||
**/ | ||
protected $applied_label; | ||
|
||
/** | ||
* Array of arguments to pass register_post_status(); | ||
* | ||
* @var array | ||
**/ | ||
protected $args = array(); | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param string $post_status Name of the Custom Post Status | ||
* @param array $post_types Array of Posts Types to apply the Custom Post Status | ||
* @param array $args Array of arguments to pass register_post_status() function | ||
* | ||
* @return void | ||
**/ | ||
public function __construct( $post_status, $post_types, $args ) { | ||
$this->post_status = $post_status; | ||
$this->post_types = $post_types; | ||
$this->action_label = isset( $args['label'] ) ? $args['label'] : $post_status; | ||
$this->applied_label = isset( $args['applied_label'] ) ? $args['applied_label'] : $this->action_label; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -1 |
||
$this->args = $args; | ||
|
||
// Removes the arguments that do not belong to register_post_type | ||
unset( $this->args['applied_label'] ); | ||
|
||
if( ! isset( $this->args['label_count'] ) ) { | ||
$this->args['label_count'] = _n_noop( $this->applied_label . ' <span class="count">(%s)</span>', $this->applied_label . ' <span class="count">(%s)</span>' ); | ||
} | ||
|
||
// Register post status | ||
add_action( 'init', array( $this, 'register_post_status' ) ); | ||
|
||
// Add meta tags to pass args | ||
add_action( 'admin_head', array( $this, 'meta_tags' ) ); | ||
|
||
// Load scripts | ||
add_action( 'admin_enqueue_scripts', array( $this, 'scripts' ) ); | ||
|
||
} | ||
|
||
/** | ||
* Register the Custom Post Status with Wordpress ;) | ||
* | ||
* @param string $post_status The name of Custom Post Status. | ||
* @param array $args Array of arguments to pass register_post_status() | ||
* | ||
* @return void | ||
**/ | ||
public function register_post_status() { | ||
register_post_status( $this->post_status, $this->args ); | ||
} | ||
|
||
/** | ||
* Add meta tags to JS | ||
* | ||
* @return void | ||
*/ | ||
public function meta_tags() { | ||
$screen = get_current_screen(); | ||
if( ! in_array( $screen->post_type, $this->post_types ) ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -1 |
||
return; | ||
|
||
$args = array( | ||
'postTypes' => $this->post_types, | ||
'appliedLabel' => $this->applied_label, | ||
'slug' => $this->post_status, | ||
); | ||
if( $screen->base === 'post' ) { | ||
global $post; | ||
if( is_object( $post ) && $post->post_status === $this->post_status ) { | ||
$args['select'] = true; | ||
} | ||
} | ||
printf( '<meta class="odin-custom-status-meta" value="%s" />', esc_attr( json_encode($args) ) ); | ||
} | ||
|
||
/** | ||
* Load post status scripts and inject JS vars | ||
* | ||
* @return void | ||
*/ | ||
public function scripts() { | ||
// Load admin JS | ||
wp_enqueue_script( 'odin-custom-status', get_template_directory_uri() . '/core/assets/js/admin-custom-status.js', array( 'jquery' ), null, true ); | ||
|
||
} | ||
|
||
/** | ||
* Update the text on edit.php to be more | ||
* descriptive of the type of post | ||
* | ||
* @param array $states An array of post display states. | ||
* @return void | ||
**/ | ||
public function display_post_status_text( $states ) { | ||
global $post; | ||
|
||
$status = get_query_var('post_status'); | ||
|
||
if( $status !== $this->post_status && $post->post_status === $this->post_status ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -1 |
||
return array( $this->applied_label ); | ||
|
||
return $states; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1
Use o
forEach
aqui.each
é bastante lento.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fdaciuk Como posso usar forEach pra percorrer elementos, pode me dar um exemplo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.