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

hityr5yr on "How to popup a message to users after downloading my plugin?"

$
0
0

Hi all,

Could anyone suggest me how to make my plugin so that users get message with some instructions after downloading or updating it?

Thank you!


Outdoorsmen on "Role based CSS"

$
0
0

I have been wanting to change the css based on a person's role. Specifically, hide (display:none;) different segments based on who.

I found this code which appears to do what I want, but I'm not familiar enough with WordPress methods to know where exactly it looks for the style sheet.

Any explanation on how and where this is done would be greatly appreciated.

add_action('admin_head','load_editor_style');
load_editor_style()
{
$templateuri = get_template_directory_uri();
 if(current_user_can('editor')){
 wp_enqueue_style('editorstyle', $templateuri.'/css/editorstyle.css');
  }
}

pouyarezaei on "Using get_option"

$
0
0

Hi everyone

I'm making a WordPress Plugin, and I'm starting with the Admin Settings page, I have the page setup and in the menu bar, i have also added sections and fields in to the page and they all work fine, when i change values of the fields and save the page and refresh the settings are the same, which tells me they are being saved. Correct?!

Now, when i try to call the settings, i cannot get a proper value! On the settings page i have 1 checkbox and one text field, i cannot get the value for either one!

The code i am using to get the value is these below, none of them work:

<?php
if(get_option( 'main_dashboard_check' ) ? get_option( 'main_dashboard_check' ) : 'no'){echo 'yes';}else{echo 'no';};
?>

I have also tried:

<?php

$main_dashboard_check = get_option( 'main_dashboard_check' );
var_dump( $main_dashboard_check ); /* outputs false if the value does not exist */

?>

This one just returns bool(false) regardless of whether the checkbox is checked or not.

<?php

$main_dashboard_check = get_option( 'main_dashboard_check', 'default_value' );
var_dump( $main_dashboard_check ); /* outputs 'default_value' if the value does not exist */

?>

This one just returns string(13) "default_value", the number of digits in the bracket change depending what i put in there as the default value! Again this shows the same message regardless of whether the checkbox is checked or not!

My code for the admin page handling this is:

<?php
function admin_init() {

register_setting( $this->settings_field, $this->settings_field, array($this, 'sanitize_theme_options') );
add_option( $this->settings_field, Media_Press_Settings::$default_settings );

add_settings_section('mediapress_main', '',
array($this, 'main_section_text'), 'main_settings_page');

add_settings_field('main_text', 'Main Text',
array($this, 'render_main_text'), 'main_settings_page', 'mediapress_main');

add_settings_field('main_dashboard_check', 'Title',
array($this, 'render_main_checkbox'), 'main_settings_page', 'mediapress_main',
array('id' => 'main_dashboard_check', 'value' => 'yes', 'text' => 'Test Checkbox') );

}

function render_main_checkbox($args) {
$id = 'mediapress_options['.$args['id'].']';
?>
<input name="<?php echo $id;?>" type="checkbox" value="<?php echo $args['value'];?>" <?php echo isset($this->options[$args['id']]) ? 'checked' : '';?> /> <?php echo " {$args['text']}"; ?>
<?php
}
?>

Can someone tell me what I'm doing wrong? Ive been at it for 2 days and everywhere i try and find an answer I end up with the same results !!

I appreciate your time.

Shunarjuna on "Temporary attributes in tinyMCE editor"

$
0
0

When you insert a link in the wp editor it automatically receives a data-mce-href attribute. However, this attribute is not saved or reflected in the text editor.

How can I reproduce this with my own attributes?

I have managed to insert the custom attribute where I need it but the problem is that it gets saved in the output and I don't want this.

kacper3355 on "Hide social buttons on mobile devices"

$
0
0

Hello. I'm using a plugin called "Simple Social buttons" that I need to hide on mobile devices (on width ~400px). Does anyone have any idea how can I achieve that?

I tried to do it by adding following code to the style.css file but it didn't worked :(
@media (max-width:400px) { .simplesocialbuttons { display: none; } }

Examplary post on my site (buttons are visible at the top of post) - http://goo.gl/KYVyFr

Thanks for any help, I really need to deal with it quickly!

Adult Casting Network on "JWplayer and Dropbox"

Jayce53 on "WP Customizer - Prevent live preview"

$
0
0

How do I prevent a widget being updated in the customizer preview if a widget field fails a JS validation check? More generally, how can the default behaviour (trigger a preview change on any widget field input) be prevented?

empolio on "Settings API: Plugin custom options page sends me to blank page"

$
0
0

I set up a custom options menu for a plugin. The form is displayed correctly. When I submit it, the options are saved, but I'm only seeing a blank page. What do I have to do to show the same page again when submitting the form?

This is the code in the main plugin file (callback functions omitted):

add_action('admin_menu', 'eeh_add_menus');
function eeh_add_menus() {
	add_menu_page('EE Helper', 'EE Helper', 'manage_options', 'ee-helper/admin/main.php');
	add_submenu_page('ee-helper/admin/main.php', 'Options', 'Options', 'manage_options', 'ee-helper/admin/options.php');
}

add_action( 'admin_init', 'eeh_register_settings' );
function eeh_register_settings() {
	register_setting('eeh_options', 'eeh_options', 'eeh_validate');

	add_settings_section(
		'eeh_notification_section',
		'Notification settings',
		'eeh_settings_section_callback',
		'eeh_options'
	);

	add_settings_field(
		'eeh_send_notifications_field',
		'Enable notifications',
		'eeh_send_notifications_field_render',
		'eeh_options',
		'eeh_notification_section'
	);

	add_settings_field(
		'eeh_notification_email_field',
		'E-mail address',
		'eeh_notification_email_field_render',
		'eeh_options',
		'eeh_notification_section'
	);
}

And this is the code in admin/options.php:

<div class="wrap">
	<?php
	if (!isset($_REQUEST['settings-updated']))
		$_REQUEST['settings-updated'] = false;

	if (false !== $_REQUEST['settings-updated']) :
		?><div class="updated fade"><p><strong>Options saved.</strong></p></div><?php
	endif;
	?>

	<h2><?php echo esc_html(get_admin_page_title()); ?></h2>

	<form method="post" action="options.php">
		<?php
		settings_fields('eeh_options');
		do_settings_sections('eeh_options');
		submit_button();
		?>
	</form>
</div>

charlyanderson on "'if' statements"

$
0
0

Hello,

I am not very good with PHP and hoped someone might be able to help me out with an if statement I am trying to implement.

Now I am trying to make it so that the WooCommerce cart only shows when there are products in. The code I have so far is:

<?php global $woocommerce; if ( sizeof( $woocommerce->cart->cart_contents) > 0 ) {

					} else { ?>

					<div class="header-cart-inner">
					  <a class="cart-contents" href="<?php echo WC()->cart->get_cart_url(); ?>" title="<?php _e( 'View your shopping cart' ); ?>"><?php echo sprintf (_n( '%d item', '%d items', WC()->cart->cart_contents_count ), WC()->cart->cart_contents_count ); ?> - <?php echo WC()->cart->get_cart_total(); ?></a>
					</div>
					<?php } ?>

It occured to me that I have the statments the wrong way round, the code above shows the cart when it's empty, hides it when there is something in the cart.

Problem is, when I swap the HTML into the stop statement, I get syntax errors and it doesn't work. It looks as if it doesn't accept HTML in that bit. Can anyone help me, thanks to anyone in advance that can.

TiagoGoncalves on "RSS Chanel Title and Link for a Custom Post Type"

$
0
0

On a normal WordPress website this is how the main rss file looks like:

<rss (...)>
  <channel>
    <title>WEBSITE NAME</title>
    <atom:link href="http://website.com/feed" rel="self" type="application/rss+xml"/>
    <link>http://website.com/feed</link>

If it's a feed of a category it looks like this:

<rss (...)>
  <channel>
    <title>WEBSITE NAME » CATEGORYNAME</title>
    <atom:link href="http://website.com/feed" rel="self" type="application/rss+xml"/>
    <link>http://website.com/feed</link>

If it's for the custom post feed, for example "Events", it will will look like this:

<rss (...)>
  <channel>
    <title>WEBSITE NAME » Posts</title>
    <atom:link href="http://website.com/feed" rel="self" type="application/rss+xml"/>
    <link>http://website.com/feed</link>

1) Is it possible to change the channel>title from "WEBSITE NAME » Posts" to "WEBSITE NAME » Events"?

2) Is it possible to change the channel>atom and channel>link from "http://website.com/feed" to "http://website.com/events/feed"?

Thank you in advance for your help!

vcgs on "Wordpress 4.2.1 pre_get_comments doesn't work after update"

$
0
0

I have this code working all time but, after updating to Wordpress 4.2.1, this doesn't work.

// return just the missing replies in the comment table
add_action( 'pre_get_comments', array( $this, 'return_missing_list' ) );
public function return_missing_list( $comments = array() ) {

    // bail on anything not admin
    if ( ! is_admin() )
        return;

    // only run this on the comments table
    $current_screen = get_current_screen();

    if( 'edit-comments' !== $current_screen->base )
        return;

    // check for query param
    if ( ! isset( $_GET['missing_reply'] ) )
        return;

    // now run action to show missing
    $comments->query_vars['meta_key']   = '_cnrt_missing';
    $comments->query_vars['meta_value'] = '1';
    $comments->query_vars['date_query'] = array(
                'after' => '10 months ago'
            );

    // Because at this point, the meta query has already been parsed,
    // we need to re-parse it to incorporate our changes
    $comments->meta_query->parse_query_vars( $comments->query_vars );
} // end missing_reply_list

Can you help me about please?

Thanks!

tinfoiler on "More tag links to seperate domain"

$
0
0

Hi,

Im trying to customise the <!--more--> tag to link to a seperate domain.

The site currently runs on domain1.com however when someone clicks 'Read More' i want it to link through to domain2.com.

I currently use the following code in functions to customise the wording of the more tag;

//custom read more.
add_filter( 'the_content_more_link', 'modify_read_more_link' );
function modify_read_more_link() {
return '<a class="more-link" href="' . get_permalink() . '"><i>Continue Reading</i></a>';
}

Can the above code be updated to link to a second domain? I do not have much php coding experience. If anyone could advise it would be appreciated!

wpDavy on "Taxonomy custom fields"

$
0
0

Hi!

Firstly, sorry for my bad english.

I'm new here and I need to make sure my choice is good.

I add custom post type "books" in my wordpress installation
I want to add the publisher like a taxonomy and I want to add more information about publisher : link to the official website, the number of known best sellers and probably other in the future.

To add these information to my taxonomy, I found this :
taxonomy_add_form_fields
It does exactly what I want, but I don't found anything in codex.wordpress... I don't want to choose this solution if this hooks will be deprecated in the future WP versions...

What do you think ? Can I use it or not ?

Thanks.

maelga on "Assign post category automatically based on author"

$
0
0

Hi,

I would like to automatically assign a category to a post based on the author’s ID.

I have tried to start from this thread:
https://wordpress.org/support/topic/automatically-add-posts-to-a-category-conditionally?replies=4
but that code alone does not work.

I have also looked at hacking this plugin that works (https://wordpress.org/plugins/author-category/) with which an author can be assigned a category manually in backend, but I have to admit this is beyond my current skills.

Has anyone any idea how to achieve this?

NathanielFisher on "Problem getting meta_value data from database"

$
0
0

Hi. I'm trying to put together a list of all posts where the metadata matches a specific query. It appears to work fine until I try to output the data, at which point it is repeated continuously.

I expected it to display 16 23 but instead it shows 16 23 16 23 16 23 16 23 16 23 16 23 16 23 16 23 16 23 16 23

Here's the code:

<?php
global $wpdb;
$results =$wpdb->get_results("SELECT post_id FROM $wpdb->posts , $wpdb->postmeta where  $wpdb->postmeta.meta_value = '2015/06/03' AND meta_key='mymvkey'", OBJECT);

foreach ($results as $result){
print_r ($result->post_id);
}
?>

I'm still trying to get the hang of handling arrays (and not just in php) so that's probably where I'm going wrong. But every post I've read suggests that this should work. Also, I've tried it both in and out of the loop with the same result. Is there any way to just display the data once instead of repeatedly?


andonovn on "jQuery can't select widget's AJAX appended HTML"

$
0
0

I am writing my first plugin and I am experiencing weird problem:

I am using shortcode to display front-end data and I have some DIV elements there that will trigger AJAX requests. The response from those requests is displayed in a widget. So far so good.
The response, however is also a HTML that contains DIV elements. And to some of them I want to apply AJAX requests on click. And this is not working.
However, if I put the exact same HTML content directly into the widget instead of using AJAX, it works. This is how I understood that jQuery can't select widget's AJAX appended HTML.
So far I tried:
- Putting my second ajax function as parameter to jQuery(document).ready() method
- Using jQuery find() method
- Loaded jQuery and my JS files in the footer (as explained in the codex)

PS I am using my ajax according to the codex and I think the problem is not there.
PS2 If you couldn't understand my case (I know I explained it in a bad way): I am trying to build something like shopping cart. I put the shopping cart as a widget and I am good adding products in it. The problem is that I can't now remove a single product from the cart because jQuery can't select the widget's appended HTML. But if I put a button to clear all products into the widget it works great.

Sorry for the long post, any help is appreciated :)

admiralchip on "How to prevent double form submission?"

$
0
0

Hi,

I'm building a custom plugin that involves submitting data using a form. The form works quite well but it is susceptible to double submission. How can I prevent double form submission?

I used this. It disables the submit button but it prevents inserting of the values into the database table:

<form ... onsubmit="myButton.disabled = true; return true;">

How can I fix this?

Thanks in advance!

viniciustsantos on "How to force a permalink to a file plugin"

Franco on "Plugin development: Is this allowed as a plugin welcome screen?"

$
0
0

Hi guys,

I am new to plugin development in wordpress. Over the past few months I have been working in building a company which offers extensions for woocommerce, these extensions have a lite and a pro version. I plan to host the lite versions in wordpress.org.

Together with every lite extension, I wan to bundle a welcome screen. This screen will show other available extensions and themes from my company, status of the license and license activation, link to documentation and support forums, etc.

The way I have envision it to work would be like this example from a premium plugin I own: http://youtu.be/eaXyxn3tb50. This is the mockup of my welcome screen: http://bit.ly/1BzTQws

Now my questions:

* Concerning the refreshing of available extensions and themes, I know that wordpress.org don't like the plugin calls to external servers. Would this be an acceptable situation for doing so? If not, I can always code the available extensions on the screen so that there is no call to my server, just though that this would be a better way since it updates on the spot.

* Concerning the ajax install of extensions, is this possible to accomplish when the download comes from wordpress repository? All the plugins I've seen doing this download from their own server since they are premium extensions

* Lastly, on the management of the welcome screen itself. I plan to bundle it with every plugin. In many cases I have seen this sort of functionality under Addons submenu of plugins (Menu "Plugin name" -> "Addons"), however in my case it makes a lot more sense to have only one menu for it, since it will be the same for all plugins. The question is what is the best way to display the latest version of the welcome screen when an user clicks on the menu? I'm thinking about a possible scenario where an user has plugin 1 and plugin 2, and plugin 2 comes with a more updated version of the welcome screen.

Many thanks for your input!

Best regards,
Fran

oyedepo1 on "Making a form independent of each category"

$
0
0

Hello,

I have been looking for the solution to this problem but hasn't found one.

This is my problem...

I have many Categories on my blog, and I want people to subscribe to my list base on their interest.

For example, Health and Technology Categories will have different opt-in forms whenever a post under this Category is opened.

Pls is there a plugin I can use for this purpose?

Thanks.

Viewing all 8245 articles
Browse latest View live




Latest Images