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

triplecomp on "Want to create filter the_content with"

0
0

Hi all,
I am trying to put together a filter for the_content so that I can add <!--nextpage--> to every post


Ethan Jinks O'Sullivan on "How do I find images with no dimensions set?"

0
0

Backstory
Using the WordPress the_content tag, I am running a custom function to search for all images that do not have a width and height attribute set and insert the proper dimensions. Below is the function:

add_filter( 'the_content', 'add_img_dimensions' );

function add_img_dimensions( $image_no_dimensions ) { // Insert width & height to images missing dimensions
    if ( preg_match_all( '/<img [^>]+>/i', $image_no_dimensions, $result ) ) {
        // print_r( $result ); // DEBUG: print all images that don't have a dimension

        preg_match_all( '/(alt|title|src)=("[^"]*")/i', $image_no_dimensions, $img );
        list( $width, $height, $type, $attr ) = getimagesize( str_replace( "\"", "" , ( $img[2][0] ) ) );
        $imgname = str_replace( "\"", "" , ( $img[2][0] ) );
    }

    return sprintf( '<img src="%s" width="%dpx" height="%dpx" />', str_replace("\"", "" , ( $img[2][0] ) ), $width, $height );
}

For example, if there is an image on one of my pages that looks like the following:

<img src="https://link.to/sum/img.jpg" alt="Image Title" />

It will then insert the width and height of the actual image:

<img width="150" height="50" src="https://link.to/sum/img.jpg" alt="Image Title" />

This functions works as expected. However, the images that already have a width and height set disappear on the page for some reason. As you can see on line three of my code, I've added an if statement to run the function only to images with no dimensions set:

if ( preg_match_all( '/<img [^>]+>/i', $image_no_dimensions, $result ) )

Except I am having trouble figuring out the regular expression (regex) to use to have preg_match_all identify only images with no dimensions set.

Objective
What is the regex that I would need to use to identify images with no dimensions in my if statement? If there is a better way to identify it, please provide me your input.

Thanks.

1725rwr on "How do I change a comment post_id after the comment has been edited?"

0
0

I have added a custom field to the comments form and have saved the data as meta data. I want to change the post_id for the comment based on this meta data. I can do this when the comment is posted by hooking comment_post:

add_action( 'comment_post', 'save_comment_meta_data' );

		function save_comment_meta_data( $comment_id ) {
  			if ( ( isset( $_POST['area'] ) ) && ( $_POST['area'] != '') )
  			$area = wp_filter_nohtml_kses($_POST['area']);
  			add_comment_meta( $comment_id, 'area', $area );

  			// my function to get a post_id appropriate for this data
  			$area_id = get_id_from_area( $area );

  			// set the post_id to the page corresponding to the area name
  			wp_update_comment(array('comment_ID' => $comment_id,
  										'comment_post_ID' => $area_id ));

		}

This works just fine.

I also want to do this when a comment is edited since the editor may change the value in the custom field. I have hooked edit_comment to update the meta data after the comment has been edited and that works fine. I tried to also change the post_id in this this function and I end up with this:

add_action( 'edit_comment', 'extend_comment_edit_metafields' );
		function extend_comment_edit_metafields( $comment_id ) {

  			if ( ( isset( $_POST['area'] ) ) && ( $_POST['area'] != '') ) :
  				$area = wp_filter_nohtml_kses($_POST['area']);
  				update_comment_meta( $comment_id, 'area', $area );
  			else :
  				delete_comment_meta( $comment_id, 'area');
  			endif;

  			// my function to get a post_id appropriate for this data
  			$area_id = get_id_from_area( $area );

  			// set the post_id to the page corresponding to the area name
  			wp_update_comment(array('comment_ID' => $comment_id,
  										'comment_post_ID' => $area_id ));
		}

The problem is that wp_update_comment() also hooks edit_comment so I have created an infinite loop by calling wp_update_comment() from within my function. The post_id does get updated, but the page eventually dies when it runs out of resources.

After some searching I thought the filter comment_save_pre would work but that only allows me to modify the content.

Is there a way for me to update a comment's post_id after it has been edited?

johnlarsen on "Ninja Forms Administrator Email not received"

0
0

I am using Ninja Forms Version 2.9.56.2 and the form will not send to my email. The submissions only show up in the "Submissions" tab on the plugin. I already selected "Admin Email" to send all submissions to my email under the "Email & Actions" tab when editing the form.

Also, the input text for the form is white on a white background. I cannot find anywhere in the CSS to change the input text color.

Website: http://www.accuratedrill.com

yaffar on "Get meta of custom post type for WP REST API"

0
0

I have been working with the WP REST API for the past two months and everything was going so well, I'm working on a custom post type that has some custom fields that didnt show in the rest like normally would with the WP_Post but I managed to use the add_filter() to retrieve the meta that I needed and it worked and everything was great, but now I'm trying to create my own Custom Routes and I can pull the meta that is included in the WP_Post query but not the custom fields. Is there a way to access the data on the filters? The custom post type I have it in a php file and the custom routes in another. Is that a motive for what I can't do it?

bradklosterman on "APIs for JS-templated custom Sections and Panels"

0
0

Wordpress advises against using php to build panels for the theme customizer. How do I implement custom panels and dynamic sections using the JS API?

Blutarsky on "Ajax callback and shortcode functionality"

0
0

I see that some people are having troubles using shortcodes in Ajax callbacks as apparently the Ajax instance is run in a different environment than usual.

Advices are more than one, many of them contradictory. You may be warned to declare wp.load.php to allow proper environment in the callback along with other includes.

Can someone clarify the legends and the truths about this argument?

  1. Is it a bad habit calling a shortcode from an Ajax callback, and if so why
  2. What are the requirements to gain a fully qualified wordpress environment inside an ajax callback. What are the bare minimum includes required to achieve this.
  3. What are the pitfalls to avoid and possible performance impacts
  4. why

If someone may clarify these aspects the whole community may benefit from this :-)

pmbs on "Remove access to Wordpress Plugin with custom role"

0
0

I have created a custom role in WordPres admin with the same capabilities as an admin account. Then I have used remove_cap() to remove capabilities that I dont want the user to see.

Though the plugin "BackWPUp" is still accessable for the user through the menu.

I have removed capabilities like edit_plugins etc. as from the Codex, but I cant find any way to remove access to specific plugins.


benoitf92 on "how to modify link and mail to reset password ?"

0
0

Dear,

With the lostpassword link I get wrong link wit error message:
"Your password reset link does not appear to be valid. Please request a new link below."

In my email the link does not contains user_login value

How can I solve the mail generation ? or Url generation problem ?
Its looks like a problem in link and mail generation for the reset password form.

I would like also to modify the content of the email.

Which function or file I need to hack ?

samalfaro on "Set ID on submenu on Max Mega Menu?"

0
0

Hi. I've been messing around for a few days now with the submenu to keep in open when the a sub page is active. I've come so far that it keeps it open but when i added the second dropdown menu something strange happend.

Even if the second submenu is inactive, the links is still clickable (like invisible links)

I added a custom css on every page to keep the parent/submenu open but i think it crashes because the submenu doesn't have a specific ID

So my question is how do i set up a specific ID to the submenus?

zagreus on "Retrieve users and roles gives error"

0
0

I'm trying to retrieve users for a blog including their roles. When I use this, I now get an error. I'm pretty sure this worked previously before the 4.6 update.

$args = array(
            'blog_id' => get_current_blog_id(),
            'fields' => array('id', 'display_name', 'user_email', 'roles'));

        $users = get_users($args);

Here's the error I get:

WordPress database error Unknown column 'wp_users.roles' in 'field list' for query SELECT wp_users.id,wp_users.display_name,wp_users.user_email,wp_users.roles FROM wp_users INNER JOIN wp_usermeta ON ( wp_users.ID = wp_usermeta.user_id ) WHERE 1=1 AND (
  wp_usermeta.meta_key = 'wp_capabilities'
) ORDER BY user_login ASC  made by require('C:\MAMP\htdocs\web\wp\wp-blog-header.php'), wp, WP->main, WP->parse_request, do_action_ref_array, rest_api_loaded, WP_REST_Server->serve_request, WP_REST_Server->dispatch, Trainerous_Mobile_Public->{closure}, Trainerous_Mobile_Public->users_get, get_users, WP_User_Query->__construct, WP_User_Query->query

As always, any suggestions / help much appreciated.

rjaskelton on "Post Author Changing On Save"

0
0

I currently have subscriber roles creating blog posts and I as am admin have to go in and approve them and publish them. When I got in to do that it then changes to the author to be me instead of the original author. How can I make it so it keeps the original author of the post?

Meitar on "WP-API not recognizing WordPress login cookie?"

0
0

I'm developing a plugin that is starting to make use of 4.4's WP-API in a few very simple JavaScript functions. The trouble is that none of the Ajax calls execute in the context of a logged-in user, despite being loaded from a logged-in account on the traditional WP Admin dashboard.

I posted details and code excerpts on the WP StackExchange here, and I'm hoping to draw people's attention to it by posting here.

The TL;DR:

The output of my Ajax calls always runs in the context of a logged-out user. Specifically, get_current_user_id() returns 0 for all Ajax-initiated calls, despite a PHP-side var_dump(get_current_user_id()) returning the correct logged-in user ID number on the output of the page itself.

Checking document.cookie seems to confirm the absence of a login cookie on the JS side, but a var_dump($_COOKIE) shows the correct login cookie's presence.

To add to the weirdness, Firefox's Network Pane shows the full cookie, along with the login value, being sent to WordPress from the Ajax call.

What gives?

Any help you can offer either in this thread or that one would be much appreciated.

Thanks.

Guido on "Hook into archive / category template"

0
0

Hi,

I'm trying to display custom content from my event plugin on the archive/category page. So I hook into the the_content filter:

function archive_content( $content ) {
	$var1 = esc_attr__( 'First var', 'textdomain' );
	$var2 = esc_attr__( 'Second var', 'textdomain' );

	if (get_post_type() == 'event' && is_archive()) {
		$content = '<div id="mydiv">' . '<div class="myvar">' . $var1 . $var2 . '</div>' . $content . '</div>';
  	}
	return $content;
}
add_filter( 'the_content', 'archive_content' );

This works, "First var" and "Second var" (and the default post content) are displayed when viewing the archive/category page.

BUT, no styling is applied (no id and class in source code either). It's all stripped. How come?

Guido

baburman on "How to redirect every request to a single page."

0
0

I'm working on a marketing website. My requirement is that except for a few pages, every request like http://hirisemarketing.com/<anything&#62; will redirect to a page (which I've already created through wp admin) http://hirisemarketing.com/marketing. This page has a shortcode which lets me create a full-fledged dynamic code through a plugin.

Everything is good except i am unable to do the redirection. I have created rewrite rules for some of the pages as per my needs like this:

add_rewrite_rule('ads/([^/]+)?$', 'index.php?pagename=ads&adct=$matches[1]', 'top');
add_rewrite_rule('renew/([^/]+)?$', 'index.php?pagename=renew&arcd=$matches[1]', 'top');
add_rewrite_rule('image-gallery/([^/]+)?$', 'index.php?pagename=image-gallery&adpid=$matches[1]', 'top');

They are all working fine. But here I want to create the redirection as i mentioned above. I've tried many possibilities like:

add_rewrite_rule('([^/]+)?$', 'index.php?pagename=marketing&bizpermalink=$matches[1]', 'top');

but no luck. Please help!

Thanks,
baburman


Bacek on "Mulltiple shortcodes on same page"

0
0

Not sure if this is the right forum, sorry in advance.

I'm trying to do a mouseover change of photos. After help from wp forums I managed to put together a shortcode which actually works. Almost. The problem is when I try to use same shortcode on same page with different parameters it doesn't work anymore. Shortcode in functions.php is

<?php
function roll_me_over_shortcode( $atts ) {
    $atts = shortcode_atts( array(
        'normal' => 'url/to/normal-not-set-photo.jpg',
        'hover' => 'url/to/hover-not-set-photo.jpg',
	'link' => 'url'
    ), $atts, 'roll-me-over' );

    ob_Start();
    ?>

<a href="'<?php echo esc_attr( $atts['link'] ); ?>'" target="_top"
   onmouseover="document.sub_but.src='<?php echo esc_attr( $atts['hover'] ); ?>'"
   onmouseout="document.sub_but.src='<?php echo esc_attr( $atts['normal'] ); ?>'">
    <img src='<?php echo esc_attr( $atts['normal'] ); ?>'
         style="width:250px; height:250px; border:0px solid #cc3300;"
         alt="Move your mouse over me" name="sub_but" />
</a>

    <?php
     return ob_get_clean();
}
add_shortcode( 'roll-me-over', 'roll_me_over_shortcode' );

and when I put only one shortoced per page it works like it should. But if I put two or more it only displays photo, without mouseover change. So when I put
[roll-me-over link="url to page" normal="photo1" hover="photo2"] it works, but when I put more, so

[roll-me-over link="url to page" normal="photo1" hover="photo2"]
[roll-me-over link="url to page 2" normal="photo3" hover="photo4"]

it doesn't work anymore. Any suggestions?

geez1 on "Add content after $content"

0
0

I am trying to do something pretty simple but I can't seem to get it to work I think I have followed the codex but I must have done something wrong I can't see.

In the wordpress admin I have added a few lines of text to one page (id=5) and I want to add a simple form that I have coded in a seperate php file after this text. This is the code I have in my custom functions file in my child theme. It all works - BUT - the form appears above the page text and I want it to appear after.

function notifications_page($content) {
 if (is_page('5')) {
	include get_stylesheet_directory() . '/notifications_functions.php';
}
  return $content;
}
add_filter('the_content', 'notifications_page');

Modifiedcontent on "Get latest posts from all sites across multisite network"

0
0

I tried to post this elsewhere on the WordPress forums, I think that broke some rules again. Mercy!

What is the latest, best solution to get recent posts from across a multisite network on your central home page?

The network-latest-posts plugin is not a solution; it requires you give it blog ID's from the blogs in your network.

I am looking for an aggregator that automatically collects the latest posts from dozens, maybe hundreds of sites, without killing the server.

The solution should probably use wp_get_sites() + get_last_updated().

This proof-of-concept snippet is floating around:

<?
$blogs = get_last_updated();
echo '
<h1>Last posts in network</h1>
';
foreach ($blogs AS $blog) {
echo "
<h2>".$blog["domain"].$blog["path"]."</h2>
";
switch_to_blog($blog["blog_id"]);
$lastposts = get_posts('numberposts=1');
foreach($lastposts as $post) :
setup_postdata($post);
the_title();
endforeach;
restore_current_blog();
}
?>
`

This post from 2011 has some kind of solution, but it is producing an annoying syntax error and I can't figure out how to fix it:

http://www.smashingmagazine.com/2011/11/wordpress-multisite-practical-functions-methods/

So what is the latest? Has anyone else worked on this? Can someone put this together, point me in the right direction?

I have another old multisite network latest posts aggregator script that I could post, but it looks very messy.

dfnorris on "Restrict Page Access to Return from PayPal"

0
0

A little while ago I created a website that I wanted to restrict access to a certain page after payment from PayPal. I am currently going through the process of configuring the website using WordPress and I am struggling with it.

The code I used for my previous website is below:-

<?php
session_start();
include ("connect.php");
include_once("pp_config.php");
include_once("paypal.class.php");

if($_SESSION['fromProcess'] == "false"){
   //send them back
   header("Location: play.php");
}
else{
   //reset the variable
   $_SESSION['fromProcess'] = "false";
}

$uid = $_SESSION['uid'];
$txn = $_SESSION['token'];

if( (!isset($_SESSION['uid'])) && (!isset($_SESSION['token'])) ){
    header('Location: http://test.com/index.php') ;
	//stop executing the script
	exit();
}
?>

Is there a way to do something similar with WordPress?

Thanks

yogyogi on "What to do with previous metas when changing All Meta Tags to Yoast Plugin"

0
0

I have a website http://www.yogihosting.com, in this website i am using All Meta Tags plugin and i have added - keywords, titles and descriptions to all my post and pages. Now i have found that the Plugin developer is asking everyone to change the plugin with some other SEO plugin because he is not going to create a new version of it from now onwards.

I therefore decided to change it with Yoast plugin. I want to ask, will there be an SEO problem on changing it? ALso i have 80+ post and pages so will the yoast will automatically take the previous seo tags or will i have to enter the SEO tags again one by one ?

Thanks

Viewing all 8245 articles
Browse latest View live




Latest Images