New answers tagged

0

You can change the global site language under Settings > General, but then edit your user account to set the admin language to whatever you want for your user account. For more info reference https://wptavern.com/wordpress-4-7-to-introduce-user-specific-language-setting-for-the-admin


1

This is an answer based on the term "Executing plugin" in your question title. If you just want to run/execute a plugin for user roles, you don't need to prevent it from loading. My solution is to let WordPress load your plugin and manage it in your plugin. So, you could have codes like this: // In the main plugin file that loads and initiate plugin ...


2

There's an action hook, pre_post_update that gets executed just before updating a post. add_action('pre_post_update', function($post_id, $data)){ if(!isset($_POST['date_start']){ wp_safe_redirect("post.php?post={$post_id}"); die(); } } I didn't find any action that gets executed right before creating a post, however, I did find a filter that ...


0

I just ran into this exact issue and with a tiny bit of tweaking it should work, what you have is 90% of the way there. I've tweaked your code slightly so it should now work. The PHP: add_action('admin_enqueue_scripts', 'joermo_enqueue_scripts'); function joermo_enqueue_scripts($hook) { $joermo_code['ce_html'] = wp_enqueue_code_editor(array('type' =&...


0

PHP has a de-facto standard package manager called Composer. This does not only download packages (themes, plugins, the core) for you, but also solves dependency conflicts in case two of your dependencies/ packages request the same sub-package (de-duplication) and maybe even in different versions. There's the WordPress specific extension called WP Starter ...


-1

In your case you don't need any of these functions on $x, because its values are created by for loop and are safe.


2

Based on WordPress documentation for esc_attr function, it is returning a string value. So, If you need to have the integer value, you need using intval function. But, when you want to display that value or put it as part of markup, it doesn't make sense. Escape functions are useful for outputting and printing values. If you want to save a value in the ...


1

WP CLI is best tool out there to manage plugins/ themes through command line, instead of uploading plugins through FTP or admin panel. Once you Install WP-CLI on your machine then run below command and see magic. wp plugin install bbpress --activate Please check WP-CLI official documentation for further understanding.


0

Found: https://gist.github.com/squarestar/37fe1ff964adaddc0697dd03155cf0d0 as well as https://stackoverflow.com/questions/10353859/is-it-possible-to-programmatically-install-plugins-from-wordpress-theme Turns out there are quite a number of ways to do it, just not mentioned here at the wordpress stack exchange.


0

It's hard to answer that without some additional code to accompany it as those aren't WordPress core functions and could be doing anything really. Based on a previous question, I'll assume one of the plugins you're referring to is the LiquidChurch/lqd-messages plugin and I see those methods in the main plugin file. Even if this isn't the correct file, ...


1

You can't enqueue because wp_loaded is too early. To enqueue scripts and styles, you need to do it on the wp_enqueue_scripts type hooks, but because your exiting on wp_loaded, none of those hooks have fired yet. Additionally, you need to have the necessary function calls in the template for it to enqueue them into, such as wp_head or wp_footer, otherwise ...


0

There's no reason for it to be there, and it won't do anything. Only the author would know why it's there, but it's likely a mistake.


3

the async property is marked as protected, so that usually signifies that it is related more to your implementation's details rather than functionality. Ideally you would write your tests to test the public methods you have exposed. Testing that the class property you set in the constructor of one class is an instanceof what was initialized doesn't provide ...


1

In WP Admin go to Settings -> Permalinks and Save Changes. You don't need to change anything, just save. This resets wordpress rewrite rules which usually fixes 404 errors with newly added CPTs.


1

Looking at the Gutenberg code in the GitHub repo, we can look at how the inline image format is implemented: https://github.com/WordPress/gutenberg/blob/99f31cdb4ed035264e0332b72dd3a2287d93ff50/packages/format-library/src/image/index.js#L17-L30 export const image = { name, title: __( 'Image' ), keywords: [ __( 'photo' ), __( 'media' ) ], ...


1

It's not a good idea to modify plugins if you can help it, as the plugin may be upated and you will lose your changes and need to redo them. Fortunately, that is not necessary in this case anyway, as you can the filter active plugins option instead. You will need the plugin slug for this: add_filter( 'option_active_plugins', 'custom_plugin_load_filter' ); ...


0

I was able to find a solution here. Add this to $args in setup.php 'show_in_rest' => true, 'rest_base' => 'charts' Add this to the bottom of the setup.php file. fistly, you're registering the fields to get/set in the rest interface. then you're registering the specific meta data to the post_type = amchart add_action("rest_api_init"...


1

Your analysis of the problem is absolutely right. By having separate autoloaders in the theme and plugin you'll run into conflicts and only the first one being loaded. There is no easy and general solution to this, but if you control the whole stack the best solution probably is to put the whole site including WP under composer management and define the ...


0

If the GPX file is attached to the current page you can find it with get_attached_media(), e.g. $gpx_files = get_attached_media( 'application/gpx+xml' ); if ( count( $gpx_files ) >= 1 ) { echo do_shortcode ('[sgpx gpx="' . wp_get_attachment_url( $gpx_files[0]->ID ) . '"]'); } else { echo '<p class="warning">No GPX file attached!</p>...


0

Based on user35752 answer, you can even use an object method with params as callback. $args = [ [new Foo(), 'bar'], [$param1, $param2, ...] ]; $callback = function () use ($args){ call_user_func_array($args[0], $args[1]); }; add_menu_page( $page, $menu, $capability, $slug, $callback , $icon, $position)


0

I believe plugins are loaded before the theme (see here "plugins_loaded" vs "setup_theme") so the error is occurring because Helper has not loaded yet. One thing you can try is to create a child theme and add the class override there (via functions.php). You can also provide your override after the theme has loaded by hooking into "after_theme_setup" or "...


2

This is because you're not adding elements to the array. You're overwriting them: $modified_result = array(); foreach($queryresult as $result){ $modified_result['name'] = $result->name; $modified_result['address'] = $result->address; } Your loop is setting the name and address property of the $modified_result array directly, and then ...


0

This fixed my issue $set = stripslashes($set);


0

It looks that a reference to global $post; is missing at the beginning of your function widget(){}


0

Well i think you just do everything inside of TopAuthor and add_action( 'admin_menu', 'TopAuthor' );


0

return defined('WC_VERSION'); should fix since defined() accepts a string as parameter. https://www.php.net/manual/en/function.defined.php If you use: require_once($_SERVER['DOCUMENT_ROOT'].'/wp-load.php'); adjusting your path if the installation is in a subrdir you load all the WP environment including active plugins etc


0

No, constructors should not define hooks. Constructors should be used to set the initial state of the object. Hooks have nothing to do with the object's initial state, so they don't belong in the constructor. Constructors should not have "side effects", so that using new ClassName() does not affect any other parts of the program, which is what registering ...


-1

it depends on what you want to do. for example, suppose your plugin needs javascript for it to work. in this case, we can enqueue the javascript in the constructor of the Class : class My_Plugin{ function __construct (){ add_action( 'wp_enqueue_scripts', array( $this , 'my_script' ) ); } function my_script(){ // here ...


-1

You can use below code to use wp-load.php to include wp-load from any location require_once( trailingslashit( ABSPATH ) .'wp-load.php' );


0

I found out why. here is the solution: you have to activate the plugin in the tests / bootstrap.php file: $GLOBALS[ 'wp_tests_options' ] = array( 'active_plugins' => array( 'YOUR-PLUGIN/YOUR-PLUGIN.php' ) )


0

I've found a solution by myself! With two lines of code I'm now able to save all the selected images and then retrive them on the front-end. I have added an array in the JS code part: // media library script (function($){ $(document).ready(function(){ $(document).on('click', '.upload_image_button', function(e){ e.preventDefault(); var ...


1

Unfortunately there doesn't seem to be any action hooks available for adding custom checkboxes to the Menu Settings section (Github/wp-admin/nav-menus.php). For registering menu locations, you should use register_nav_menus().


0

As it turns out, WordPress actually checks to see if the data posted matches existing data, if so, don't do anything and return false. I was clicking my update button expecting it to just update in the database regardless, but it's not the case: Taken from here


0

Another way... https://developer.wordpress.org/reference/functions/media_sideload_image/ <?php $insert_post = array( 'post_author' => 1,//or get_current_user_id() 'post_status' => 'publish', 'post_type' => 'attachment', 'post_name' => 'attachment'.date('Ymd-H-i-s'), 'post_date' => date('Y-m-d H:i:s',time()), ); $post =...


0

Your action should be wp_ajax and wp_ajax_nopriv instead of admin_ajax. add_action( 'wp_ajax_new_message', array($this, 'process_upload') ); add_action( 'wp_ajax_nopriv_new_message',array($this, 'process_upload') );


0

I am working on this code for the front of an ERP application. Note that only after uploading will it be possible to insert the message. You will need to click edit to open the modal and enter the content. Maybe it's useful for you! Insert in your functions.php <?php if(!is_admin()){ if(!function_exists('ajax_upload_files')): ...


0

My suggestion is to register the activation and deactivation hook outside the class definition. /* * Fired during plugin activation. **/ class My_plugin_activator() { public static activate() { // write your db code here } } . /* * Fired during plugin deactivation. **/ class My_plugin_deactivator() { public static deactivate() { ...


1

The problem was that I have not stored the date values in the right way. I had to save it like Y-m-d or Y-m-d H:i


2

Your problem has nothing to do with apply_filters, it's a basic PHP mistake: public function init (){ $filter_fields = apply_filters('tbg_reg_fields', $this->fields); } Here, you create a brand new variable in the init method scope named $filter_fields, then never use it. $this->filter_fields and $...


2

This question Set up WP Authentication from External API has a link to a blog. That put me in the right direction and shed some light on my work (Thanks @Rup). class CustomLogin { /** * Initializes the plugin. * * To keep the initialization fast, only add filter and action hooks in the constructor. */ public function __construct()...


0

You can upload file using ajax using below code: First : Add attributes name="f-form" and id="f-form" in your <form> tag. After that, In js script, get form data using new FormData() and send to ajax data, Note : change url: ajax_object.ajaxurl with your ajax url path jQuery(document).ready(function(e) { jQuery('#f-submit').on('click', ...


1

To create shortcode write code in the your theme file functions.php function my_shortcode_fun() { $output = $class = ''; ob_start(); enter code here.... $output = ob_get_contents(); ob_end_clean(); return $output; } add_shortcode('my-shortcode', 'my_shortcode_fun');


0

You have to call TopAuthor() function in plugins_loaded orinit action. You are getting Fatal error: Uncaught Error: Call to undefined function wp_get_current_user() because wp_get_current_user() is a pluggable function. You can not call when your plugin is included. You have to wait for the action plugins_loaded or init. Call your TopAuthor() function using ...


2

Currently you can not unset key because you can not find proper key from array. The issue is that you did $stamp = array($_POST['stamp']); as array which is wrong. you have to remove array() from $stamp, so which look like $stamp = $_POST['stamp'];. then you can search value in column from array and unset it. I have tested below code which is working ...


Top 50 recent answers are included