Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all 8245 articles
Browse latest View live

gislef on "Add buttom - TinyMCE"

$
0
0

Hi

I am working with two plugins that use the Tinymce for text editing:

- WIRIS (editor of posts and pages adds button to mathematical formulas without entering codes such as latex)

- TinyMCE Visual Comment Editor (insert a small editor in the comment)

I want to add in Visual TinyMCE Comment editor the button wiris, so that the mathematical formulas button also appears in the comment editor.

Directory wp-include plugin wiris

wp-includes/js/tinymce/plugins/tiny_mce_wiris

Directory wp-content

/wp-content/plugins/tiny_mce_wiris.php

Content tiny_mce_wiris.php:

add_filter('mce_external_plugins', 'wrs_addPlugin');
add_filter('mce_buttons', 'wrs_addButtons');

function wrs_addPlugin($plugins) {
	$plugins['tiny_mce_wiris'] = get_option('home') . '/wp-includes/js/tinymce/plugins/tiny_mce_wiris/editor_plugin.js';
	return $plugins;
}

function wrs_addButtons($buttons) {
	array_push($buttons, 'separator', 'tiny_mce_wiris_formulaEditor', 'tiny_mce_wiris_CAS');
	return $buttons;
}
?>

Content code function of TinyMCE Visual Editor Comment:
/wp-content/plugins/tinymce-visual-editor-comment/function.php

<?php
require_once('setting.php');
$mobilesp = get_option('mobilesp');
if ($mobilesp=="mobilesp"){
	add_filter( 'comment_form_field_comment', 'comment_editor' );
}
else {
	if( !wp_is_mobile() )
		add_filter( 'comment_form_field_comment', 'comment_editor' );
}
function comment_editor() {
  global $post;
  ob_start();
  $rtl = get_option('ltr_rtf, tyny_mce_wiris');
  $mediabtn = get_option('mediabtn');
  if ($mediabtn=='mediabtn'){$mediabtn=true;}
  else{$mediabtn=false;}
  wp_editor( '', 'comment', array(
    'textarea_rows' => 15,
    'teeny' => true,
    'quicktags' => false,
	'media_buttons' => $mediabtn,
	'tinymce' => array('directionality' => $rtl),
  ) );

  $editor = ob_get_contents();

  ob_end_clean();

  //make sure comment media is attached to parent post
  $editor = str_replace( 'post_id=0', 'post_id='.get_the_ID(), $editor );

  return $editor;
}

// wp_editor doesn't work when clicking reply. Here is the fix.
add_action( 'wp_enqueue_scripts', '__THEME_PREFIX__scripts' );
function __THEME_PREFIX__scripts() {
    wp_enqueue_script('jquery');
}
add_filter( 'comment_reply_link', '__THEME_PREFIX__comment_reply_link' );
function __THEME_PREFIX__comment_reply_link($link) {
    return str_replace( 'onclick=', 'data-onclick=', $link );
}
add_action( 'wp_head', '__THEME_PREFIX__wp_head' );

function __THEME_PREFIX__wp_head() {
?>
<script type="text/javascript">
  jQuery(function($){
    $('.comment-reply-link').click(function(e){
      e.preventDefault();
      var args = $(this).data('onclick');
      args = args.replace(/.*\(|\)/gi, '').replace(/\"|\s+/g, '');
      args = args.split(',');
      tinymce.EditorManager.execCommand('mceRemoveEditor', true, 'comment');
      addComment.moveForm.apply( addComment, args );
      tinymce.EditorManager.execCommand('mceAddEditor', true, 'comment');
    });
  });
</script>
<?php }

function at_comment_css() {
	// This makes sure that the positioning is also good for right-to-left languages
	$x = is_rtl() ? 'left' : 'right';

	echo "
	<style type='text/css'>
	#wp-comment-editor-container {
		border: 2px solid #DFDFDF;
	}
	</style>
	";
}

add_action('wp_head', 'at_comment_css');

Please help me, how to add bottom wiris in the TinyMCE Visual Editor Comment?


cboakes on "WP_Query tax_query in plugin"

$
0
0

Hi there,

I’m attempting to write a plugin, I’m using WP_Query and am trying to do a simple tax query with the following arguments:

$args	=	array(
	'posts_per_page'	=>	-1,
	'post_type'		=>	'event',
	'tax_query' 		=>	array(
		array(
			'taxonomy' => 'event_type',
			'field'    => 'slug',
			'terms'    => ‘carnival’,
		),
	),
);

This works fine in my theme and returns the relevant results, but in my plugin it doesn’t seem to return any results.

Any help would be greatly appreciated.

Many thanks,

Chris

racemanyaya on "Get_post_meta to had image text"

$
0
0

Hi, I try to had a text "promotion" on a product image. I have create a custom field "promo" in my post-type. When the get_post_meta find the promo custom field I want ti display a small div that will show text over my prodcut image.

Here the code I have but it not working, I'm learning php.

<div class="packageImage">
<?php $promo = get_post_meta(get_the_ID(), 'promo', true); ?>
<?php if ($promo): ?>
<div class="packagePromoItem">Promotion</div>
<?php endif; ?>
<a alt="" href="<?php echo get_post_meta(get_the_ID(), 'wpcf-fichier-pdf', true); ?>" target="_blank"><img class="packageImage2" alt="" title="" src="<?php echo get_post_meta(get_the_ID(), 'wpcf-featured-images', true); ?>"></a>
</div>

briansellers on "Coding help"

$
0
0

I'm not really sure what to look for here but, I have a problem getting updates from a supplier. They allow API calls using XML but I don't know how or where to put the code to get the file or update inventory. Below is a xml code provided by the supplier. I was thinking if I built a separate page with a button on it that generated the call (POST command) then I could make that page private and would be able to get the data then upload to the products to update the products. I placed this request in this forum because there may already be an extension or add on out there that has these functions but I don't know if there is. Any ones help would be greatly appreciated because at this point, I can't update inventory.

The XML document you will send will resemble the following:

<?xml version="1.0" encoding="utf-8" ?> <inventory><ctid>5B15B4E19BAD45B7920ACB4A4064F234</ctid>
<!--the following "itemlist" container is *OPTIONAL*If you provide an "itemlist", then server will return only the items you requested, otherwise we will return all active items in our database (about 1MB response file).If you specify invalid item ID's, they will be ignored.
-->
<itemlist> <item prodid="AA02" />
<item prodid="ACXR410" />
<item prodid="AS1" />
</itemlist>
</inventory>

If there is no error, the server will respond with an inventory document similar to the following:
<?xml version="1.0" encoding="utf-8" ?>
<inventory>
<itemlist>
<item prodid="AA02" quantity="42" price="1.16" map="0.0" mfgitem="AA02" mfgname="MAPLE LEAF PRESS INC" />
<item prodid="ACXR410" quantity="0" price="321.91" map="379.99" mfgitem="775011" mfgname="EASTON TECHNICAL PRODUCTS" />
<item prodid="AS1" quantity="6" price="10.67" map="13.99" mfgitem="MBC SOX LOW S" mfgname="TEAM J SALES AND MARKETIN" />
</itemlist>
</inventory>

Example of an error:

<?xml version="1.0" encoding="utf-8" ?>
<error>
<timestamp>20080101120101</timestamp>
<errorid>-20002</errorid>
<errordata>This is your error information</errordata>
</error>

I have even tried to send this using POSTMAN but was unsuccessful, I believe because of the https: and the certificate.. Again, any help at all will be greatly appreciated. My coding skills are no where near where they need to be for this.

marchael on "remove site name in adminbar for contributors roles"

$
0
0

Hello, im new in using wordpress. For now on, I know how to hide admin bar for some users,I make my dashboard accesible only for admin,editor and author only. But i want to remove some links in admin bar. I want to remove site name links from the adminbar. so only the admin,editors and author can view it. because it is for admin, editor and author only. sorry for my wrong english grammar thanks.

Barry.moton on "myfonts installation"

$
0
0

Hi, I got a web font through myfonts but I'm unsure how to incorporate into my website. I'm using the arcade theme, and would like the font to take the place of the site title. How do I do that?

HealingMuse on "Hired wordpress admin disappeared - need access to my admin page"

$
0
0

Since last September, my hired web designer, web coder has disappeared. He has been unreachable. Finally, through TUCOWS support, I received my domain registration back, but this web master has made himself the administrator of my site and now I do not have access to the full site. His phone number is no longer in service. His snail mailing address returns mail back...
I can update blogs and pages, but nothing in the coding.
I need to back up my full site, in case he screws up anything else.

Is there a way to get in and change the administrator privileges back to me, the owner of the site?

Any guidance is greatly appreciated.
I have known this guy for over 5 years, so this is very odd and disturbing.

mathieus on "Listing pages in a loop: styling childs and child-of-childs"

$
0
0

Hi,

I'm working on a website with 1 page, but, as a matter of making the admin clear, the different topics should be divided into different pages.
I have this code for that:

<?php get_header() ?>
<?php query_posts(array('showposts' => 20, 'post_type' => 'page', 'order' => 'ASC')); while (have_posts()) { the_post(); ?>
<div><?php the_title(); ?></div>
<div><?php the_content(); ?></div>
<?php } ?>
<?php get_footer() ?>

this does as I please: showing a title and the content (which i will later make toggable).
What i would like to do is: the parent page should have a class, the childs should have a second class, child-of-childs should have a third class, so i can style all 3 depth's separately. Would this be possible with this code? I'd like to give it a list styling actually, just as the wp_list_pages does.

thanks!
Mathieu


ranipretty5 on "needs a villain like me, because"

$
0
0

I think America needs people like me," Marilyn Manson tells World Cafe host David Dye. "The world needs bad men to keep out the other bad men. And I think the world I'm the part of the movie where change happens.

CrimsonIce on "Custom Info Boxes After Each Post?"

$
0
0

Hi. I'm pretty new to WordPress so there are some parts of it I have difficulty working with. I run a small scale gaming niche website which focuses on just a small group of video games, and what I'm trying to do is have a short "game info box" at the end of each post. Basically, think of an author info box that instead of having info on the author, it has info on the game the news post is discussing. I want it to look like a box with a short text description of the game, the game name linking to a specific page (I'll be making a custom page per game), and a small icon/image of the game. A good example is what can be found at the end of posts in this WordPress website: http://www.koi-nya.net/2015/02/05/persona-5-presenta-su-primer-trailer-con-gameplay/
See how there's a Persona 5 game info box at the end of their post.

I've seen the Shortcodes Ultimate plugin and that seems to do the trick given that they have custom boxes, but I have a problem with that. Said plugin requires you to rewrite the entire info box again and again whenever you post - my site, on the other hand, has thousands of news posts that may focus on few games - making reposting a big hassle.

Hence, what I'm looking for is a plugin that may allow having a separate database for the info of the game, and then having an option or shortcode to include the info box everytime I post a new post. That way we won't have to retype it every single time. Is there such a plugin that can achieve that? Thank you.

lindalunnmiller on "serious hack - political in nature"

$
0
0

Hi - my clients site has been hacked by what appears to be a political group.

http://www.dancecoquitlam.ca

I tried restoring the website using the FTP file management function in CPANEL and the site came back but was rehacked within a couple of hours.

Is there a plugin or set of code that I can install that will block this kind of attack?

Let me know.

Thanks
-Linda

luespi on "wp website hacked it shows this image"

$
0
0

http://s17.postimg.org/7k3uw4ezz/hackedfinal.jpg

How easy or how hard do you think it will be to at least get the articles back?

I am on phpmyadmin and I think I am getting some articles text and on cpanel It seems I am getting some images

Should just start over all over again or try to retreive some content?
there wasn't that much content anyway there

neoWP75 on "Add to cart multiple products in same time"

$
0
0

Hi,

I need advices ! How to add to cart (WPshop plugin) muttiple products in same time with single button "add to cart" ? Must we use javascript, ajax or something else ? Do you have any leads on how to proceed ?

Currently, as you can see http://hospi-deces-obseques.lamonnai...com/souscrire/ I have 3 products with 3 buttons "valider" (= add to cart). So you have to click on each button if you want those 3 products in cart.

I hope I was clear in my explanations. Thank you in advance for your help.

Theme : Busiprof v1.3.7
Plugin : WP-Shop v1.3.9.1
Wordpress v4.0.1

sasherwood93 on "change image src without refresh."

$
0
0

Hi,

I have a client who I am currently developing a site for. They are wanting a custom plugin which allows their customers to visualise colors combinations for a kitchen.

My plan is to have an admin page which allows the sections for worktop, oven etc as navigation and then each color combo has a png image which is then displayed on the front end when clicked.

There will be a few layers which holds the elements again worktops, oven etc.

I am wondering is there a way I can achieved this Ajax jQuery and php but with out refreshing And changes the image src to the selected Id or featured image.

As reference I'm looking to Do something similar to this

Thanks
Stephen.

JeffSydor-BIPC on "Showing categories FROM another set of categories"

$
0
0

Here is a link to what I'm working on:
http://www.knowingimmigrationlaw.com/investor/

Right now I'm using the following code to achieve this:

if ( is_page( 'investor' ) ) {
    query_posts( 'cat=17' );
    while ( have_posts() ) : the_post();
    ?>
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php
    endwhile;
}

This is calling all post titles within the category of "investor".

What I am trying to accomplish is a bit more complicated (or at least is complicated to explain). I need to add a step in between the homepage and these pages. I need to display a list of all categories from a group of posts which also contain ONLY 2 other posts (that are not child categories).

For example: on the page above, I want all categories that appear in posts with "I AM" AND "Investor" to be listed. Let's say one of these categories is "Green Card". When you click on that, you go to a results page that shows a filtered list of posts with excerpts that feature ONLY "I AM", "Investor" and "Green Card".

If there is a simpler way to complete this please let me know also. This needs to be resolved before the end of next week so I'm in a bit of a bind.


pablo005 on "thickbox replacement"

$
0
0

Hello,

As you know in the new versions of WordPress media library doesn't use thickbox. Now it use a new modal box.

Is it possible to use this new modal box by developers for their plugins or themes?

Thanks

melanie bund on "redirect user by role"

$
0
0

Hi am trying to redirect specific users to a custom page, have tried to add different code snippets to my functions page, some dont work others send all users there - below is i presume the basic code which does not seem to work though it should?
´// Redirect editor
function wp_redirect_users_by_role() {

$current_user = wp_get_current_user();
$role_name = $current_user->roles[0];

if ( 'editor' === $role_name ) {
wp_redirect( 'http://photohunters.org/add-star' );
if ( 'administrator' === $role_name ) {
wp_redirect( 'http://photohunters.org/wp-admin' );
} // if

} // wp_redirect_users_by_role
add_action( 'admin_init', 'wp_redirect_users_by_role' ); ´

thanks Melanie

guag123 on "mobile link stopped working"

$
0
0

hi all

my website http://www.getupandgolf.co.uk which has been live now for over a year has, in the past couple of months, decided to stop working on all mobile and tablet devices and instead links to yahoo.

My friend who set up the site for me in 2013 is in thailand for a few months so im trying to sort it out myself.

have installed a couple of different mobile themes but i think something is wrong with the permalink

any help very much appreciated and a free round of golf awaits anyone who gets it sorted.. ;-)

tmw27529 on "Multiple Custom Meta Boxes & Fields"

$
0
0

I have a Custom Post Type that has multiple Custom Meta Boxes, each with multiple Custom Fields. The code is a bit overwhelming and I wondering if there might be a better way to go about doing this.

// Add the DATE OF BIRTH and DEATH DATE Meta Box
function add_bldob_meta_box() {
    add_meta_box(
        'bldob_meta_box', // $id
        'Date of Birth and Death', // $title
        'show_bldob_meta_box', // $callback
        'obituaries', // $page
        'normal', // $context
        'default'); // $priority
}
add_action('add_meta_boxes', 'add_bldob_meta_box');

// Field Array
$prefix = 'bldob_';
$bldob_meta_fields = array(
	array(
    	'label' => 'Date of Birth',
    	'desc'  => '',
    	'id'    => $prefix.'bdate',
    	'type'  => 'date'
	),
	array(
    	'label' => 'Date of Death',
    	'desc'  => '',
    	'id'    => $prefix.'ddate',
    	'type'  => 'date'
	)
);

function show_bldob_meta_box() {
global $bldob_meta_fields, $post;

// Use nonce for verification
echo '<input type="hidden" name="bldob_meta_box_nonce" value="'.wp_create_nonce(basename(__FILE__)).'" />';

    // Begin the field table and loop
    echo '<table class="form-table">';
    foreach ($bldob_meta_fields as $field) {
        // get value of this field if it exists for this post
        $meta = get_post_meta($post->ID, $field['id'], true);
        // begin a table row with
        echo '<tr>
                <th><label for="'.$field['id'].'">'.$field['label'].'</label></th>
                <td>';
                switch($field['type']) {
                    // case items will go here

					// Date of Birth
					case 'date':
						echo '<input type="text" class="datepicker" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$meta.'" size="30" />
							<br /><span class="description">'.$field['desc'].'</span>';
					break;
					// Date od Death
					case 'date':
						echo '<input type="text" class="datepicker" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$meta.'" size="30" />
							<br /><span class="description">'.$field['desc'].'</span>';
					break;

                } //end switch
        echo '</td></tr>';
    } // end foreach
    echo '</table>'; // end table
}

// Save the Data
function save_bldob_meta($post_id) {
    global $bldob_meta_fields;

    // verify nonce
    if (!wp_verify_nonce($_POST['bldob_meta_box_nonce'], basename(__FILE__)))
        return $post_id;
    // check autosave
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
        return $post_id;
    // check permissions
    if ('page' == $_POST['post_type']) {
        if (!current_user_can('edit_page', $post_id))
            return $post_id;
        } elseif (!current_user_can('edit_post', $post_id)) {
            return $post_id;
    }

    // loop through fields and save the data
    foreach ($bldob_meta_fields as $field) {
        $old = get_post_meta($post_id, $field['id'], true);
        $new = $_POST[$field['id']];
        if ($new && $new != $old) {
            update_post_meta($post_id, $field['id'], $new);
        } elseif ('' == $new && $old) {
            delete_post_meta($post_id, $field['id'], $old);
        }
    } // end foreach
}
add_action('save_post', 'save_bldob_meta');

// Add the VISITATION Meta Box
function add_blvis_meta_box() {
    add_meta_box(
        'blvis_meta_box', // $id
        'Visitation Information', // $title
        'show_blvis_meta_box', // $callback
        'obituaries', // $page
        'normal', // $context
        'default'); // $priority
}
add_action('add_meta_boxes', 'add_blvis_meta_box');

// Field Array
$prefix = 'blvis_';
$blvis_meta_fields = array(
	array(
    	'label' => 'Date',
    	'desc'  => '',
    	'id'    => $prefix.'date',
    	'type'  => 'date'
	),

	array(
        'label'=> 'Time',
        'desc'  => '',
        'id'    => $prefix.'time',
        'type'  => 'text'
    ),

	array(
        'label'=> 'Location Name',
        'desc'  => '',
        'id'    => $prefix.'text',
        'type'  => 'text'
    ),

    array(
        'label'=> 'Location Address',
        'desc'  => '',
        'id'    => $prefix.'address',
        'type'  => 'textarea'
    ),

    array(
        'label'=> 'Details',
        'desc'  => '',
        'id'    => $prefix.'textarea',
        'type'  => 'textarea'
    )
);

function show_blvis_meta_box() {
global $blvis_meta_fields, $post;

// Use nonce for verification
echo '<input type="hidden" name="blvis_meta_box_nonce" value="'.wp_create_nonce(basename(__FILE__)).'" />';

    // Begin the field table and loop
    echo '<table class="form-table">';
    foreach ($blvis_meta_fields as $field) {
        // get value of this field if it exists for this post
        $meta = get_post_meta($post->ID, $field['id'], true);
        // begin a table row with
        echo '<tr>
                <th><label for="'.$field['id'].'">'.$field['label'].'</label></th>
                <td>';
                switch($field['type']) {
                    // case items will go here

					// Date
					case 'date':
						echo '<input type="text" class="datepicker" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$meta.'" size="30" />
							<br /><span class="description">'.$field['desc'].'</span>';
					break;

					// Time
            		case "time":
    					echo '<input type="text" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$meta.'" size="30" />
        					<br /><span class="description">'.$field['desc'].'</span>';
					break;

					// location name
					case 'text':
    					echo '<input type="text" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$meta.'" size="30" />
        					<br /><span class="description">'.$field['desc'].'</span>';
					break;

					// address
					case 'address':
    					echo '<textarea name="'.$field['id'].'" id="'.$field['id'].'" cols="60" rows="4">'.$meta.'</textarea>
        					<br /><span class="description">'.$field['desc'].'</span>';
					break;

					// details
					case 'textarea':
    					echo '<textarea name="'.$field['id'].'" id="'.$field['id'].'" cols="60" rows="4">'.$meta.'</textarea>
        					<br /><span class="description">'.$field['desc'].'</span>';
					break;

                } //end switch
        echo '</td></tr>';
    } // end foreach
    echo '</table>'; // end table
}

// Save the Data
function save_blvis_meta($post_id) {
    global $blvis_meta_fields;

    // verify nonce
    if (!wp_verify_nonce($_POST['blvis_meta_box_nonce'], basename(__FILE__)))
        return $post_id;
    // check autosave
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
        return $post_id;
    // check permissions
    if ('page' == $_POST['post_type']) {
        if (!current_user_can('edit_page', $post_id))
            return $post_id;
        } elseif (!current_user_can('edit_post', $post_id)) {
            return $post_id;
    }

    // loop through fields and save the data
    foreach ($blvis_meta_fields as $field) {
        $old = get_post_meta($post_id, $field['id'], true);
        $new = $_POST[$field['id']];
        if ($new && $new != $old) {
            update_post_meta($post_id, $field['id'], $new);
        } elseif ('' == $new && $old) {
            delete_post_meta($post_id, $field['id'], $old);
        }
    } // end foreach
}
add_action('save_post', 'save_blvis_meta');

// Add the SERVICE Meta Box
function add_blser_meta_box() {
    add_meta_box(
        'blser_meta_box', // $id
        'Service Information', // $title
        'show_blser_meta_box', // $callback
        'obituaries', // $page
        'normal', // $context
        'default'); // $priority
}
add_action('add_meta_boxes', 'add_blser_meta_box');

// Field Array
$prefix = 'blser_';
$blser_meta_fields = array(
	array(
    	'label' => 'Date',
    	'desc'  => '',
    	'id'    => $prefix.'date',
		'key' => 'servicedate',
    	'type'  => 'date'
	),

	array(
        'label'=> 'Time',
        'desc'  => '',
        'id'    => $prefix.'time',
        'type'  => 'text'
    ),

	array(
        'label'=> 'Location Name',
        'desc'  => '',
        'id'    => $prefix.'text',
        'type'  => 'text'
    ),

    array(
        'label'=> 'Location Address',
        'desc'  => '',
        'id'    => $prefix.'address',
        'type'  => 'textarea'
    ),

    array(
        'label'=> 'Details',
        'desc'  => '',
        'id'    => $prefix.'textarea',
        'type'  => 'textarea'
    )
);

function show_blser_meta_box() {
global $blser_meta_fields, $post;

// Use nonce for verification
echo '<input type="hidden" name="blser_meta_box_nonce" value="'.wp_create_nonce(basename(__FILE__)).'" />';

    // Begin the field table and loop
    echo '<table class="form-table">';
    foreach ($blser_meta_fields as $field) {
        // get value of this field if it exists for this post
        $meta = get_post_meta($post->ID, $field['id'], true);
        // begin a table row with
        echo '<tr>
                <th><label for="'.$field['id'].'">'.$field['label'].'</label></th>
                <td>';
                switch($field['type']) {
                    // case items will go here

					// Date
					case 'date':
						echo '<input type="text" class="datepicker" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$meta.'" size="30" />
							<br /><span class="description">'.$field['desc'].'</span>';
					break;

					// Time
            		case "time":
    					echo '<input type="text" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$meta.'" size="30" />
        					<br /><span class="description">'.$field['desc'].'</span>';
					break;

					// location name
					case 'text':
    					echo '<input type="text" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$meta.'" size="30" />
        					<br /><span class="description">'.$field['desc'].'</span>';
					break;

					// address
					case 'address':
    					echo '<textarea name="'.$field['id'].'" id="'.$field['id'].'" cols="60" rows="4">'.$meta.'</textarea>
        					<br /><span class="description">'.$field['desc'].'</span>';
					break;

					// details
					case 'textarea':
    					echo '<textarea name="'.$field['id'].'" id="'.$field['id'].'" cols="60" rows="4">'.$meta.'</textarea>
        					<br /><span class="description">'.$field['desc'].'</span>';
					break;

                } //end switch
        echo '</td></tr>';
    } // end foreach
    echo '</table>'; // end table
}

// Save the Data
function save_blser_meta($post_id) {
    global $blser_meta_fields;

    // verify nonce
    if (!wp_verify_nonce($_POST['blser_meta_box_nonce'], basename(__FILE__)))
        return $post_id;
    // check autosave
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
        return $post_id;
    // check permissions
    if ('page' == $_POST['post_type']) {
        if (!current_user_can('edit_page', $post_id))
            return $post_id;
        } elseif (!current_user_can('edit_post', $post_id)) {
            return $post_id;
    }

    // loop through fields and save the data
    foreach ($blser_meta_fields as $field) {
        $old = get_post_meta($post_id, $field['id'], true);
        $new = $_POST[$field['id']];
        if ($new && $new != $old) {
            update_post_meta($post_id, $field['id'], $new);
        } elseif ('' == $new && $old) {
            delete_post_meta($post_id, $field['id'], $old);
        }
    } // end foreach
}
add_action('save_post', 'save_blser_meta');

Here is a link to the site

I want to make sure I am doing things the best efficient way. The site currently works great for the client but I really want to be able to showcase it as an awesome custom WordPress solution (like in the WP community & with other developers).
Any suggestions are greatly appreciated!

Alex on "publish_future_post not running"

$
0
0

Hi, I've combed the forums and various results found via Google, but have yet to find a solution to an issue I have when trying to take action when a scheduled post is published. The code is pretty simple, so I hope I'm missing something obvious here.

The goal: when a sticky post is published, remove the sticky flag from all other posts, so there is only one published sticky post at a time. It's important that this only executes at the time the new sticky post is published, not saved/scheduled, as there should always be one sticky post visible.

The code:

add_action('publish_post', 'custom_sticky_save_post');
add_action('publish_future_post', 'custom_sticky_save_post');

add_action( 'auto-draft_to_publish', 'custom_sticky_save_post' );
add_action( 'draft_to_publish', 'custom_sticky_save_post' );
add_action( 'future_to_publish', 'custom_sticky_save_post' );
add_action( 'new_to_publish', 'custom_sticky_save_post' );

function custom_sticky_save_post($post_id) {
    if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    $sticky = isset($_POST['sticky']) && $_POST['sticky'] == 'sticky';
    if($sticky) {
        $sticky_posts = array($post_id);
        update_option('sticky_posts', $sticky_posts);
    }
}

This executes properly for sticky posts that are published immediately, but does nothing when a scheduled post publishes, so the previous sticky post(s) remains sticky. At present, this is all on my theme's functions.php file, but once I resolve this, I will wrap it in a plugin for anyone to use. I think this should work solely with the first two add_actions, but I've included the others in an attempt to find something that works.

Thanks in advance!

Viewing all 8245 articles
Browse latest View live




Latest Images