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

Rob Gelhausen on "Enqueue CSS Into Specific Admin Page"

$
0
0

I am trying to enqueue a CSS style sheet (and .js file) on a specific Admin Page).

I have gone through the WP documentation found here - Plugin API/Action Reference/admin enqueue scripts .

Below is my code. This code is almost verbatim from the WP documentation. There is no file being enqueued into the head of plugin when I implement the below code. When I change != $hook to == $hook, the style sheet is enqueued into the head of every admin page. Any help would be greatly appreciated.

function wpgel_localseo_bootstrap_styles($hook) {
	if ( 'plugins.php' != $hook ) {
        return;
    }

wp_enqueue_style( 'wpgel_localseo_bootstrap_styles', plugins_url( 'wpgel-localseo/css/bootstrap.min.css' ) );

}
add_action( 'admin_head', 'wpgel_localseo_bootstrap_styles' );

Ellimist91 on "Post being updated as draft instead of being submitted with AJAX validation"

$
0
0

I'm using code from this answer to validate some fields for a custom post type before it's submitted for review as well as it's published. Here's my code -

//AJAX to validate allocation request before publishing
//From http://wordpress.stackexchange.com/questions/42013/prevent-post-from-being-published-if-custom-fields-not-filled?lq=1
//Adapted from http://wordpress.stackexchange.com/questions/15546/dont-publish-custom-post-type-post-if-a-meta-data-field-isnt-valid
add_action('admin_enqueue_scripts-post.php', 'ep_load_jquery_js');
add_action('admin_enqueue_scripts-post-new.php', 'ep_load_jquery_js');
function ep_load_jquery_js(){
global $post;
if ( $post->post_type == 'allocation_req' ) {
    wp_enqueue_script('jquery');
}
}

add_action('admin_head-post.php','ep_publish_admin_hook', 100);
add_action('admin_head-post-new.php','ep_publish_admin_hook', 100);
function ep_publish_admin_hook(){
global $post;
if ( is_admin() && $post->post_type == 'allocation_req' ){
    ?>
    <script language="javascript" type="text/javascript">
        jQuery(document).ready(function() {
            jQuery('#publish').click(function() {
                if(jQuery(this).data("valid")) {
                    return true;
                }
                var form_data = jQuery('#post').serializeArray();
                var data = {
                    action: 'ep_pre_submit_validation',
                    security: '<?php echo wp_create_nonce( 'pre_publish_validation' ); ?>',
                    form_data: jQuery.param(form_data),
                };
                jQuery.post(ajaxurl, data, function(response) {
                    if (response.indexOf('true') > -1 || response == true) {
                        jQuery("#post").data("valid", true).submit();
                    } else {
                        alert("Error: " + response);
                        jQuery("#post").data("valid", false);

                    }
                    //hide loading icon, return Publish button to normal
                    //jQuery('#ajax-loading').hide();
                    jQuery('#publish').removeClass('button-primary-disabled');
                    jQuery('#save-post').removeClass('button-disabled');
                });
                return false;
            });
        });
    </script>
    <?php
}
}

add_action('wp_ajax_ep_pre_submit_validation', 'ep_pre_submit_validation');
function ep_pre_submit_validation() {
    //simple Security check
    check_ajax_referer( 'pre_publish_validation', 'security' );

    //convert the string of data received to an array
    //from http://wordpress.stackexchange.com/a/26536/10406
    parse_str( $_POST['form_data'], $vars );

    echo 'true'; die();
}

Now, the post is being saved, but it's status is not being changed as a result of "Publish" or "Submit for Review". I can manually change it's status using the quick edit function, but it does not happen as a result of pressing the "Submit" button.

PS: This is a similar question without any answers.

lisapike on "Code to make site mobile-friendly"

$
0
0

Is it possible for me to add code into my Word Press site to make it mobile-friendly, rather than use a plug-in?

Michael on "svn screwed up?"

$
0
0

Hi,
I've been working on my plugin for a while today (2mb autocode -- http://wordpress.org/plugins/2mb-autocode), and I just noticed something odd. When I updated the svn repo to version 1.2.1 of my plugin, it updated in the svn trunk, even sent me an email that I had changed things in the repo, but the tag 1.2.1 does not appear, and wordpress still says download version 1.2 on the plugin page. Even weirder is when I go to http://plugins.svn.wordpress.org/2mb-autocode, then click on tags, only 1.0 is displayed. Any idea what could be going on? I've checked svn info and the URL's match, and svn checkin produces no output (so presumably I've already checked in everything).
The weirdest thing is, even though tag 1.0 is the only one in the repository, wordpress still recognizes 1.2, 1.1.2, 1.1.1, and 1.1. I have no clue why it's not recognizing 1.2.1, but I think this tags being missing has something to do with it.
Thanks,
-Michael.

iamjoshing on "Show parent-child relationship for categories in the wordpress admin"

$
0
0

How can I show child categories under there parent category in the wordpress admin? On a post the format of the category box would look like this:

Category 1
-Sub-Category 1.1
-Sub-Category 1.2
Category 2

little_lulu on "wp_inser_post does not return postid in wp ajax call"

$
0
0

Hi,

I was using the wp ajax call and got it to work. But I only encountered a problem when using the wp_insert_post. The post was created but the function does not return a postid. I put an echo in my function to return the postid but there is no response. Any ideas on what is causing this? This is my first time using the wp ajax call.

dgcov on "wp_update_user causes lockout."

$
0
0

Hi,

I'm updating user information using `
$user_id=wp_update_user($user_data);`

I'm setting data using:

$user_data->first_name=$form_data['first_name'];
      $user_data->user_nicename=$form_data['first_name'];
      $user_data->last_name=$form_data['last_name'];
      $user_data->display_name=$form_data['first_name'].' '.$form_data['last_name'];
      $user_data->nickname=$form_data['nickname'];

I'm not supplying the user's password.

After these changes the user is unable to log in.

JoliOliOli on "Wordpress Conventions: Pages, DB access & templates?"

$
0
0

I am recently coming to building stuff on top of Wordpress after a more traditional PHP framework background. I've tried to look at how other people do it, but I'm still unsure of what I should be doing in the following situations:

1) Interactive pages: If I want to create a special one-off dynamic page to be accessed at one URL, do I create it as a template and make a page using that template, a shortcode and make a page using that shortcode, or another method?

2) Database access: Is the best way to do it to use $wpdb? No PDO or anything like that?

3) Templating: I create a shortcode to take some data and render it into something for displaying. How/where should I put the HTML to keep it seperate from the shortcode code itself?
Many thanks!


odie2 on "Use "page" post type for data only"

$
0
0

Hello,

I am creating very advanced form that have to be easy possible to add new/edit sections and subsections.

I did it with Advanced Custom Fields plugin and "page" post type as it's nice to use page hierarchy and page order. (Display appropriate boxes from ACF and use hierarchical functions in loops.)

Problem is that pages should be treated as "not exists", so only for ACF data, galleries (I am using them for creating inputs in form) etc.

Alternatively I could rebuild them on custom post type, but I have some bad experience from past that it often get broken. And I would be "free" from my client with such problems. Or maybe I used wrong plugins?

However, what's the correct way to use posts for "store" data only?
Should I migrate to custom post type or did some tricks like following?

function rr_404_my_event() {
  global $post;
  // Match if is that page is child used only for data
  if ( $statement ) {
    global $wp_query;
    $wp_query->set_404();
    status_header(404);
  }
}
add_action( 'wp', 'rr_404_my_event' );

If so, anyone knows function to exclude them from Yoast SEO's XML Sitemap (not by ID, as client could add more sections) and add them noindex?

Example structure what I am talking about:

  1. Page with form visible for user
    1. Def First section's data (page order 1)
      1. Subsection of above
    2. Abc Second section's data (page order 2)

Thanks in advance for advices!
Greetings

odie2 on "previous/next_post_link post format when post has no format"

$
0
0

Hello,

I am using at end of post, navigation to previous and next post of certain post type.

<?php

if ( is_page() ) :

    previous_post_link( '%link', __( '<span class="meta-nav">Previous Page</span>%title', 'twentyfourteen' ) );
    next_post_link( '%link', __( '<span class="meta-nav">Next Page</span>%title', 'twentyfourteen' ) );

elseif ( false !== get_post_format() ) :

    previous_post_link( '%link', __( '<span class="meta-nav">Previous '. ucfirst( get_post_format() ) .'</span>%title', 'twentyfourteen' ), TRUE, ' ', 'post_format' );
    next_post_link( '%link', __( '<span class="meta-nav">Next '. ucfirst( get_post_format() ) .'</span>%title', 'twentyfourteen' ), TRUE, ' ', 'post_format' );

else :

    previous_post_link( '%link', __( '<span class="meta-nav">Previous Post</span>%title', 'twentyfourteen' ) );

    next_post_link( '%link', __( '<span class="meta-nav">Next Post</span>%title', 'twentyfourteen' ) );

endif;

?>

But when post has no format, get_post_format() returns false and as I checked in core, there are no any trick, even with filters on wp_get_object_terms as it's getting results from on _term_relationships.

I just would to:

<- Prev Gallery | Current Gallery | Next Gallery ->
<- Prev No-Format Post | Current No-Format Post | Next No-Format Post ->

I could even use any plugin if exists.

Thanks in advance!
Greetings

odie2 on "Pagination: posts limited only on first page"

$
0
0

Hello,

According to https://wordpress.org/support/topic/front-page-query_posts-limit-posts-only-on-first-page-1
I found that 5 posts from offset are not displayed on last page - they needs next page.

I have 408 published posts.
So $wp_query->max_num_pages = 41.

But index.php is:

global $query_string;

$front_limit = 5;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$offset = ( is_paged() ? ( ($paged - 2) * $posts_per_page + $front_limit ) : 0 );
$posts_per_page = get_option('posts_per_page');

$my_query = '&ignore_sticky_posts=1';
$my_query .= '&offset='.$offset;
$my_query .= '&paged='.$paged;

if ( !is_paged() ) :
    $my_query .= '&posts_per_page='.$front_limit;
else :
    $my_query .= '&posts_per_page='.$posts_per_page;
endif;

query_posts( $query_string . $my_query );

So on 41 pages I have 405 posts (41 pages limited to 410 posts, but front page takes only 5 posts and following pages have offset by those 5 taken from front page).
And 3 last posts are missing.

Correctly number of pages should be:

$front_limit = 5;
$total_posts = $wp_query->found_posts;
$posts_per_page = get_option('posts_per_page');

$total_pages = ceil( ( $total_posts - $front_limit ) / $posts_per_page ) + 1;

I have no problem to modify navigation to set max number of pages 42, but page 42 just no exists.

Temporarily I just used trick for last page (41):

if ( !is_paged() ) :
    $my_query .= '&posts_per_page='.$front_limit;
else :
    if ( $paged == $wp_query->max_num_pages ) $posts_per_page += $front_limit;

    $my_query .= '&posts_per_page='.$posts_per_page;
endif;

So page 41 displays up to 15 posts (in my case 13).

But this is not satisfactory result. If someone have an idea, please let me know.

Note: fix for first page posts navigation is

$args = array_merge( $wp_query->query_vars, array( 'showposts' => get_option('posts_per_page')) );
query_posts( $args );

before call of "paginate_links"

Thanks in advance!
Greetings

tobbger on "Changing Facebook description when shared"

$
0
0

My blog has no text in the posts (it's basically sound and image based) and therefore the description I get on Facebook when sharing a post is:

You may use these HTML tags and attributes: <abbr title=""> <acronym title=""> <b>...

I would like the description box to be empty. It should only view the post title and the image from the post (each post has it's own image). I've tried to download plugins like WP Open Graph to sort this out, but I can't get it to work.

What's the easiest way to only change the description text for each post when sharing it on Facebook? I want the headline and the image to be what the post has already.

A. J. on "translate"

$
0
0

Hi Guys,
I created about 90 pages, and I have the same text between <a> tag

I need to change the only one word of this text to another word.
How can i do that ? please

I used :

add_filter( 'gettext', 'my_text_strings', 20, 3 );
function my_text_strings( $translated_text, $text, $domain ) {
    switch ( $translated_text ) {
        case 'BMX:' :
            $translated_text = __( 'NIS', 'text' );
            break;
         }
return $translated_text;
}

But it is not working, I think the wrong with: 'text' , but I don't know which value must i add instead of.
Please, help ?
Regards
A-.J.

KAMedia on "Theme Settings Admin Page"

$
0
0

Hello, not sure if this is the correct place to put this topic, however I suspect that it is since it's more to do with development than actual theme troubleshooting.

Anyways, I have a static front-page (front-page.php) that currently displays one post in the "Front-Page" category. While this works fine I would like to migrate that intro paragraph "post" into the actual theme settings.

Is it possible to do this? Or should I just leave it the way that I have it coded now where it queries one most recent post in the "Front-Page" category.

Thanks!

helloadorable on "Whose responsibility is it to deal with ipv6 addresses? Plugin author or host?"

$
0
0

I just finally nailed some sporadic bugs with two WordPress plugins I use which happen to store users ip addresses.

The problem in both cases is that the developer setup a varchar(25) length database column to store ip addresses in and occasionally an ip address comes through in big long ipv6 format. So when a database insert happens that includes the ip address as part of the data being inserted, the insert just silently fails.

Both plugin authors told me that I should configure my web host setup so that $_SERVER[REMOTE_ADDR] always return an ipv4 ip address and never an ipv6.

But my web host says that any code written that can only accommodate ipv4 ip addresses is severely out of date.

Here are example of the two kinds of ip addresses if you're not familiar.

Example IPv4 address: 104.16.0.1
Example IPv6 address: 2400:cb00:f00d:dead:beef:1111:2222:3333

What's your take on this? I'm just curious.


chibimaddy on "Modified Category Page Now Only Shows 1 Post"

$
0
0

I have modified a category page in multiple ways, one step at a time, and all worked until I modified it so that when there are NO posts it will show a placeholder graphic.
-When there is NO post, the placeholder graphic shows (as is desired).
-When there is a post, the placeholder graphic does not show, and the post does (as is desired).

The problem is, if there is more than one post, the page will still only return one post.

<?php get_header(); ?>
<div id="content">
<?php the_post(); ?>
<?php rewind_posts(); ?>
<?php if ( have_posts() ) : the_post();?>
<div id="complete_entry">
<div id="td1_replace">
<a href="<?php the_permalink(); ?>" target="_top" title="<?php the_title();?>">
<?php
if ( has_post_thumbnail() ) {
  $thumbnail_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'thumbnail' );
  echo '<div id="thumbnail_background" style="background-image:url(' . $thumbnail_url[0] . ');">';
}
?>
<img src="/adopt/wp-content/themes/chibitude2014/images/purple_frame.png" id="frame_overlay">
</a>
</div>
<!--end td1_replace-->

<div id="td2_replace">
<a href="<?php the_permalink(); ?>" target="_top" title="<?php the_title();?>">
<?php the_title();?></a>
<?php get_template_part ('entry','summary');?>
<?php $args = array(
    'number' => 1,
    'post_id' => $post->ID,
    'status' => 'approve'
);
$latest_comment = get_comments( $args );
if( $latest_comment ) foreach( $latest_comment as $comment ) {
/*whatever you want to show from the comment, for instance*/ ?>
High Bid:<?php echo $comment->comment_content; ?>
<?php } ?>
</div>
<!--end "td2_replace"-->

</div>
<!--end "complete_entry"-->

<?php else :
echo "";
?>
<div id="empty" style="margin:25px auto;text-align:center;"><img src="../2014/~images/2015ChunkUnavailable.png"></div>
<?php endif; ?>
</div>
<!--end "content"-->

<div id="pagination">
<?php wp_pagination(); ?>
</div>
<?php get_footer(); ?>

Here is the page in question:
http://chibitude.com/adopt/?cat=248

ccprog on "How to block Network Activation for a plugin"

$
0
0

Since I know my plugin will not work when it is activated network-wide on a multisite, I try not to tempt admins by blocking this method.

My attempt was pretty straight-forward:

function crw_install ( $network_wide = null ) {
    if ( $network_wide ) {
        trigger_error( 'Please activate the plugin individually on each site.', E_USER_ERROR );
    }
    /* more code */
}
register_activation_hook( CRW_PLUGIN_FILE, 'crw_install' );

Well, it did work in the sense that the plugin does not get activated, but the error message displayed says

Cannot redeclare crw_install() ...

and it seems this is logged once for each existing site.

Is there a better way to achieve this, or even to avoid the "Network Activate" link showing up at all?

rikideveloper on "Hack my website"

$
0
0

Hello, i have a problem with my old work of wordpress, i was created an ecommerce website with woocommerce, a one year ago, since yesterday the site has completely stopped running , I can no longer open the page including the panel in control , what can be ?

scooter1 on "Media Window Display"

$
0
0

I'm trying to hide the items in the left "Insert Media" column in the media uploader window. -> Image
The site has roles and I am using the "Frontier Restrict Media" plugin, however, the plugin does not remove the option to create gallery, set featured image, etc. Is there a way to prevent the media window from calling in those options?

Thanks

Mansi on "Preserve post before wp_reset_postdata"

$
0
0

Hi,

I have a plugin which resets post data using wp_reset_postdata().
But I want to access same post data at another point after the reset.
Is there any way that I can achieve that?

Viewing all 8245 articles
Browse latest View live




Latest Images