我为myCRED创建了这个插件,以便在用户根据帖子中的附件数量发布帖子时给出一些分数。它正在工作,但问题是我无法更改myCred挂钩首选项中的“creds”和“log”!它们不会更新。
add_filter( \'mycred_setup_hooks\', \'image_count_hook\' );
function image_count_hook( $installed ) {
$installed[\'images_count_hook\'] = array(
\'title\' => \'images count for published posts\',
\'description\' => \'when user publishes a post, counts the number of images\',
\'callback\' => array( \'images_in_post_hook\' )
);
return $installed;
}
add_action(\'mycred_init\', \'load_image_count_hook\' );
function load_image_count_hook() {
class images_in_post_hook extends myCRED_Hook {
// Construct
function __construct( $hook_prefs, $type = \'mycred_default\' ) {
parent::__construct( array(
\'id\' => \'number_of_images_in_post\',
\'defaults\' => array(
\'image_count\' => array(
\'creds\' => 70,
\'log\' => \'%plural% for images\'
),
)
), $hook_prefs, $type );
}
// Hook into WordPress
public function run() {
if ( $this->prefs[\'image_count\'][\'creds\'] != 0 )
add_action( \'transition_post_status\', array( $this, \'count_images_in_post\' ), 30, 3 );
}
// Check if the user qualifies for points
public function count_images_in_post( $new_status, $old_status, $post ) {
$ID = $post->ID;
$user_id = $post->post_author;
$post_type = $post->post_type;
// Check for exclusions
if ( $this->core->exclude_user( $user_id ) === true ) return;
// check if post is newly published
if ( ! ($new_status == \'publish\' && $old_status != \'publish\' && $old_status != \'private\') ) return;
if ( $post_type != \'post\' ) return;
// Make sure this is unique event
if ( $this->core->has_entry( \'images_post_count\', $post_id, $user_id ) ) return;
$attachments = get_children( array( \'post_parent\' => $ID, \'post_status\' => \'inherit\', \'post_type\' => \'attachment\', \'post_mime_type\' => \'image\', \'order\' => \'ASC\', \'orderby\' => \'menu_order ID\' ) );
$total_attachments = count( $attachments );
// Execute
$this->core->add_creds(
\'images_post_count\',
$user_id,
$this->prefs[\'image_count\'][\'creds\'] * $total_attachments,
$this->prefs[\'image_count\'][\'log\'],
$post_id,
\'\',
$this->mycred_type
);
}
// Add Settings
public function preferences() {
// Our settings are available under $this->prefs
$prefs = $this->prefs; ?>
<label class="subheader" for="<?php echo $this->field_id( array(\'image_count\' => \'creds\') ); ?>"><?php echo $this->core->plural(); ?></label>
<ol>
<li>
<div class="h2"><input type="text" name="<?php echo $this->field_name( array(\'image_count\' => \'creds\') ); ?>" id="<?php echo $this->field_id( array(\'image_count\' => \'creds\') ); ?>" value="<?php echo $this->core->number( $prefs[\'image_count\'][\'creds\'] ); ?>" size="8" /></div>
</li>
</ol>
<label class="subheader" for="<?php echo $this->field_id( array(\'image_count\' => \'log\') ); ?>"><?php _e( \'Log template\', \'mycred\' ); ?></label>
<ol>
<li>
<div class="h2"><input type="text" name="<?php echo $this->field_name( array(\'image_count\' => \'log\') ); ?>" id="<?php echo $this->field_id( array(\'image_count\' => \'log\') ); ?>" value="<?php echo $prefs[\'log\']; ?>" class="long" /></div>
</li>
</ol>
<?php }
}
}
我找不到问题。请帮忙